home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Information / CSMP Digest / volume 3 / csmp-digest-v3-115 < prev    next >
Text File  |  1995-12-31  |  122KB  |  3,432 lines

  1. C.S.M.P. Digest             Fri, 06 Oct 95       Volume 3 : Issue 115
  2.  
  3. Today's Topics:
  4.  
  5.         6-byte xDEFs - still a valid technique?
  6.         Apple Camera API
  7.         AppleScript recursiveness
  8.         Code to copy files?
  9.         Debugging tips?  Here's one!
  10.         GWorlds = 8k overhead?
  11.         How to Find System Folder on Startup Volume
  12.         How to convert a raster image into a PICT?
  13.         How to loop QT movies?
  14.         Novice Tech Tip #1 - SetRect.
  15.         Obscure FILEID question
  16.         Q: FindFolder won't link
  17.         Resource size limits?
  18.         [Q] MPW and printf()...Again
  19.         how do I get char minus any modifier key alterations?
  20.  
  21.  
  22.  
  23. The Comp.Sys.Mac.Programmer Digest is moderated by Francois Pottier
  24. (pottier@clipper.ens.fr).
  25.  
  26. The digest is a collection of article threads from the internet newsgroups
  27. comp.sys.mac.programmer.help, csmp.tools and csmp.misc. It is designed for
  28. people who read news semi-regularly and want an archive of the discussions.
  29. If you don't know what a newsgroup is, you probably don't have access to
  30. it. Ask your systems administrator(s) for details. If you don't have access
  31. to news, you may still be able to post messages to the group by using a
  32. mail server like anon.penet.fi (mail help@anon.penet.fi for more
  33. information).
  34.  
  35. Each issue of the digest contains one or more sets of articles (called
  36. threads), with each set corresponding to a 'discussion' of a particular
  37. subject.  The articles are not edited; all articles included in this digest
  38. are in their original posted form (as received by our news server at
  39. nef.ens.fr).  Article threads are not added to the digest until the last
  40. article added to the thread is at least two weeks old (this is to ensure that
  41. the thread is dead before adding it to the digest).  Article threads that
  42. consist of only one message are generally not included in the digest.
  43.  
  44. The digest is officially distributed by two means, by email and ftp.
  45.  
  46. If you want to receive the digest by mail, send email to listserv@ens.fr
  47. with no subject and one of the following commands as body:
  48.     help                                Sends you a summary of commands
  49.     subscribe csmp-digest Your Name     Adds you to the mailing list
  50.     signoff csmp-digest                 Removes you from the list
  51. Once you have subscribed, you will automatically receive each new
  52. issue as it is created.
  53.  
  54. The official ftp info is //ftp.dartmouth.edu/pub/csmp-digest.
  55. Questions related to the ftp site should be directed to
  56. scott.silver@dartmouth.edu.
  57.  
  58. -------------------------------------------------------
  59.  
  60. >From rdwells@mmm.com (Richard Wells)
  61. Subject: 6-byte xDEFs - still a valid technique?
  62. Date: 7 Sep 1995 20:28:31 GMT
  63. Organization: 3M Company
  64.  
  65. Back in the olden days, before Apple and IBM were on speaking
  66. terms and when Copland was most famous as a composer, there
  67. was a technique that some of us used for LDEFs whereby we
  68. would add a 6-byte LDEF to the application's resource fork,
  69. with the first 2 bytes being a 680x0 JMP instruction and the
  70. remaining 4 being garbage.  Then before using it we would read
  71. in the LDEF, make it non-purgeable, and patch the last 4 bytes
  72. to contain a pointer to the "real" entry point for the LDEF,
  73. which was a routine in one of our application's code segments.
  74.  
  75. (I'm using LDEF for illustration, even though I think this
  76. technique was used for CDEFs, WDEFs, and MDEFs as well.)
  77.  
  78. My questions are:
  79.  
  80. (1)  Can this technique be used on a Power Mac, in native
  81. mode?  I realize that the op-code changes, and that it may
  82. have to be an 8-byte (or whatever) resource, but can the
  83. basic technique be used after adjusting for these differences?
  84.  
  85. (2)  Will Copland disallow this?  My guess would be yes, since
  86. as the OS becomes more robust, things like writing values into
  87. code segments and/or executing data segments become verboten.
  88.  
  89. And, for that matter:
  90.  
  91. (3)  Was this ever a good idea?  It has the feeling of a really
  92. nasty kludge, but boy, was it useful.  (The xDEF could access
  93. the application's globals (after setting A5?), and it made
  94. debugging MUCH easier.)  I can't remember where I first heard
  95. of the technique, but I think it was an "official" Apple source
  96. (e.g. an article in Develop, a Tech Note, or a note from DTS
  97. in response to a question I had).
  98.  
  99. Any e-mail responses that do not duplicate posted responses will
  100. be summarized.
  101.  
  102.  
  103. >From rdwells@mmm.com (Richard Wells)
  104. Subject: 6-byte xDEFs - still a valid technique?
  105. Date: 7 Sep 1995 20:28:31 GMT
  106. Organization: 3M Company
  107.  
  108. Back in the olden days, before Apple and IBM were on speaking
  109. terms and when Copland was most famous as a composer, there
  110. was a technique that some of us used for LDEFs whereby we
  111. would add a 6-byte LDEF to the application's resource fork,
  112. with the first 2 bytes being a 680x0 JMP instruction and the
  113. remaining 4 being garbage.  Then before using it we would read
  114. in the LDEF, make it non-purgeable, and patch the last 4 bytes
  115. to contain a pointer to the "real" entry point for the LDEF,
  116. which was a routine in one of our application's code segments.
  117.  
  118. (I'm using LDEF for illustration, even though I think this
  119. technique was used for CDEFs, WDEFs, and MDEFs as well.)
  120.  
  121. My questions are:
  122.  
  123. (1)  Can this technique be used on a Power Mac, in native
  124. mode?  I realize that the op-code changes, and that it may
  125. have to be an 8-byte (or whatever) resource, but can the
  126. basic technique be used after adjusting for these differences?
  127.  
  128. (2)  Will Copland disallow this?  My guess would be yes, since
  129. as the OS becomes more robust, things like writing values into
  130. code segments and/or executing data segments become verboten.
  131.  
  132. And, for that matter:
  133.  
  134. (3)  Was this ever a good idea?  It has the feeling of a really
  135. nasty kludge, but boy, was it useful.  (The xDEF could access
  136. the application's globals (after setting A5?), and it made
  137. debugging MUCH easier.)  I can't remember where I first heard
  138. of the technique, but I think it was an "official" Apple source
  139. (e.g. an article in Develop, a Tech Note, or a note from DTS
  140. in response to a question I had).
  141.  
  142. Any e-mail responses that do not duplicate posted responses will
  143. be summarized.
  144.  
  145.  
  146.  
  147. +++++++++++++++++++++++++++
  148.  
  149. >From Jim.Matthews@dartmouth.edu (Jim Matthews)
  150. Date: Fri, 08 Sep 1995 09:05:38 -0500
  151. Organization: Dartmouth College
  152.  
  153. In article <42nklf$q3o@dawn.mmm.com>, rdwells@mmm.com (Richard Wells) wrote:
  154.  
  155. >(1)  Can this technique be used on a Power Mac, in native
  156. >mode?  I realize that the op-code changes, and that it may
  157. >have to be an 8-byte (or whatever) resource, but can the
  158. >basic technique be used after adjusting for these differences?
  159.  
  160. A slightly different technique, which is actually cleaner, can be used. 
  161. You don't want to put PPC opcodes in your xDEF resource, since the Toolbox
  162. expects to find 68k code there.  But you can replace the 6-byte xDEF stub
  163. with a 32-byte routine descriptor that points to your native routine. 
  164. Here are the macros I used to do this in Fetch:
  165.  
  166. #define  POWER_LDEF_OFFSET    1000  /* offset to PowerPC LDEF stubs */
  167.  
  168. #ifdef __powerc
  169. #define  NATIVE_LDEF_ID(x) (x + POWER_LDEF_OFFSET)
  170. #define  LDEF_ADDR_OFFSET  20       /* offset into routine desc */
  171. #define  FLUSH_LDEF_STUB()          /* routine desc is data, no flushing */
  172. #else
  173. #define  NATIVE_LDEF_ID(x) (x)
  174. #define  LDEF_ADDR_OFFSET  2        /* offset into jump instruction */
  175. #define  FLUSH_LDEF_STUB() if (TrapAvailable(0xA198)) { FlushDataCache();
  176. FlushInstructionCache(); }
  177. #endif
  178.  
  179. and the initialization code:
  180.  
  181.    h = GetResource('LDEF', NATIVE_LDEF_ID(BOOKMARK_LDEF_ID));
  182.    *(long *) (*h + LDEF_ADDR_OFFSET) = (long) BookmarkLDEF;
  183.    FLUSH_LDEF_STUB();
  184.  
  185. You can copy the stub resources/routine descriptors out of a copy of Fetch
  186. (available for downloading from <ftp://ftp.dartmouth.edu/pub/mac/>).
  187.  
  188. >(2)  Will Copland disallow this?  My guess would be yes, since
  189. >as the OS becomes more robust, things like writing values into
  190. >code segments and/or executing data segments become verboten.
  191.  
  192. Copland will support existing xDEFs, so I'd expect these techniques to
  193. keep working.  The OS will be more robust, but it won't stop you from
  194. changing the contents of resources in your own heap.  But Copland-savvy
  195. apps won't use custom xDEFs, they'll override SOM classes, so the
  196. motivation for stub xDEFs will go away.
  197.  
  198. >And, for that matter:
  199. >
  200. >(3)  Was this ever a good idea?
  201.  
  202. I think it was a great idea.  What I'd question is the decision to require
  203. stand-alone resources for something as simple as drawing list cells.  A
  204. simple callback would have made everyone's life easier.
  205.  
  206. -- 
  207. Jim Matthews
  208. Dartmouth Software Development
  209. <http://www.dartmouth.edu/pages/softdev/>
  210.  
  211. +++++++++++++++++++++++++++
  212.  
  213. >From owenh@harlequin.com (Owen Hartnett)
  214. Date: Fri, 8 Sep 1995 18:08:15 GMT
  215. Organization: Harlequin, Inc.
  216.  
  217. In article <42nklf$s13@dawn.mmm.com>, rdwells@mmm.com (Richard Wells) wrote:
  218. > My questions are:
  219. > (1)  Can this technique be used on a Power Mac, in native
  220. > mode?  I realize that the op-code changes, and that it may
  221. > have to be an 8-byte (or whatever) resource, but can the
  222. > basic technique be used after adjusting for these differences?
  223.  
  224. When I asked this same question a few months back, others pointed me to
  225. the NewsWatcher source, which seems to have a PowerPC friendly
  226. implementation.
  227. > (2)  Will Copland disallow this?  My guess would be yes, since
  228. > as the OS becomes more robust, things like writing values into
  229. > code segments and/or executing data segments become verboten.
  230.  
  231. I certainly hope not, for the following reasons: 1) it would not take too
  232. much effort to maintain it the way it is, 2) the advantages of using it
  233. are significant and 3) they'd break a whole lotta applications.
  234. > And, for that matter:
  235. > (3)  Was this ever a good idea?  It has the feeling of a really
  236. > nasty kludge, but boy, was it useful.  (The xDEF could access
  237. > the application's globals (after setting A5?), and it made
  238. > debugging MUCH easier.)  I can't remember where I first heard
  239. > of the technique, but I think it was an "official" Apple source
  240. > (e.g. an article in Develop, a Tech Note, or a note from DTS
  241. > in response to a question I had).
  242.  
  243. I first heard of it from something Larry Rosenstein posted, who was on the
  244. MacApp team at the time. Of course, most Apple folk post personally and do
  245. not represent the company. I also heard Mike Kahl, the father of Think C,
  246. also recommend it at a BCS meeting way long ago.
  247.  
  248. -Owen
  249.  
  250. +++++++++++++++++++++++++++
  251.  
  252. >From ari@shore.net (Ari Halberstadt)
  253. Date: Fri, 08 Sep 1995 19:11:18 -0400
  254. Organization: North Shore Access/Eco Software, Inc; (info@shore.net)
  255.  
  256. In article <42nklf$s13@dawn.mmm.com>, rdwells@mmm.com (Richard Wells) wrote:
  257.  
  258. >Back in the olden days, before Apple and IBM were on speaking
  259. >terms and when Copland was most famous as a composer, there
  260. >was a technique that some of us used for LDEFs whereby we
  261. >would add a 6-byte LDEF to the application's resource fork,
  262. >...
  263.  
  264. Here's some code from a popup CDEF that does not require a separate
  265. resource and works with 68K and PPC versions. Similar code can be used for
  266. LDEFs.
  267.  
  268. /* Creates a glue handle for 68k or PowerPC. */
  269. void PopupGlueInit(PopupGlueUnion *glue, ProcPtr proc, ProcInfoType info)
  270. {
  271.    #if GENERATINGPOWERPC
  272.       RoutineDescriptor descriptor = BUILD_ROUTINE_DESCRIPTOR(0, 0);
  273.       glue->ppc.descriptor = descriptor;
  274.       glue->ppc.descriptor.routineRecords[0].procInfo = info;
  275.       glue->ppc.descriptor.routineRecords[0].procDescriptor = proc;
  276.    #else
  277.       #pragma unused (info)
  278.       glue->m68k.jmp = 0x4EF9;
  279.       glue->m68k.proc = proc;
  280.       if (TrapAvailable(_HWPriv)) {
  281.          FlushInstructionCache();
  282.          FlushDataCache();
  283.       }
  284.    #endif
  285. }
  286.  
  287. Here's how it's used:
  288.  
  289. ...
  290.       /* allocate glue handle for MDEF */
  291.       tmp = NewHandle(sizeof(PatchMenuProcStructure));
  292.       if (tmp) {
  293.          (**popup).menuProc = tmp;
  294.          HLock(tmp);
  295.          PopupGlueInit(&(**(PatchMenuProcHandle) tmp).glue,
  296.             (ProcPtr) PatchMenuProc, uppMenuDefProcInfo);
  297.          HUnlock(tmp);
  298.       }
  299. ...
  300. /* A handle to this structure is installed in the menu's menuProc field. */
  301. typedef struct {
  302.    PopupGlueUnion glue; /* glue stuff */
  303.    Handle proc;         /* original MDEF handle */
  304.    short width;         /* width of menu */
  305. } PatchMenuProcStructure, **PatchMenuProcHandle;
  306.  
  307. /* Menu proc to patch the mSizeMsg, allowing us to set the menu width to
  308.    include the triangle. This is installed just before calling
  309.    PopupMenuSelect, and is removed immediately afterwards. */
  310. static pascal void PatchMenuProc(short message, MenuHandle menu,
  311.    Rect *menuRect, Point hitPt, short *whichItem)
  312. {
  313.    PatchMenuProcHandle patch;
  314.    SignedByte state;
  315.    Handle proc;
  316.    
  317.    patch = (PatchMenuProcHandle) (**menu).menuProc;   
  318.    proc = (**patch).proc;
  319.    state = HGetState(proc);
  320.    MoveHHi(proc);
  321.    HLock(proc);
  322.    (**menu).menuProc = proc;
  323.    CallMenuDefProc((MenuDefProcPtr) *proc, message, menu, menuRect, hitPt,
  324. whichItem);
  325.    (**menu).menuProc = (Handle) patch;
  326.    if (message == mSizeMsg)
  327.       (**menu).menuWidth = (**patch).width;
  328.    HSetState(proc, state);
  329. }
  330. ...
  331.       /* patch the menu's mdef to ignore the width calculated by
  332.          the mSizeMsg message */
  333.       oldMenuProc = (**(**popup).menu).menuProc;
  334.       if ((**popup).menuProc) {
  335.          PatchMenuProcHandle patch = (PatchMenuProcHandle) (**popup).menuProc;
  336.          (**(**popup).menu).menuProc = (**popup).menuProc;
  337.          (**patch).proc = oldMenuProc;
  338.          (**patch).width = menuWidth;
  339.       }
  340. ...
  341.       /* restore mdef */
  342.       (**(**popup).menu).menuProc = oldMenuProc;
  343.  
  344. -- Ari Halberstadt (ari@shore.net)
  345.  
  346. +++++++++++++++++++++++++++
  347.  
  348. >From rdwells@mmm.com (Richard Wells)
  349. Date: 11 Sep 1995 03:06:43 GMT
  350. Organization: 3M Company
  351.  
  352. Jim.Matthews@dartmouth.edu (Jim Matthews) wrote:
  353. >In article <42nklf$q3o@dawn.mmm.com>, rdwells@mmm.com (Richard Wells) wrote:
  354. >
  355. >>(1)  Can this technique be used on a Power Mac, in native
  356. >>mode?  I realize that the op-code changes, and that it may
  357. >>have to be an 8-byte (or whatever) resource, but can the
  358. >>basic technique be used after adjusting for these differences?
  359. >
  360. >A slightly different technique, which is actually cleaner, can be used. 
  361. >You don't want to put PPC opcodes in your xDEF resource, since the Toolbox
  362. >expects to find 68k code there.  But you can replace the 6-byte xDEF stub
  363. >with a 32-byte routine descriptor that points to your native routine. 
  364. >Here are the macros I used to do this in Fetch:
  365. >
  366. >[code sample deleted]
  367. >
  368. >You can copy the stub resources/routine descriptors out of a copy of Fetch
  369. >(available for downloading from <ftp://ftp.dartmouth.edu/pub/mac/>).
  370.  
  371. Thanks much for the info and code sample.
  372.  
  373. >>(2)  Will Copland disallow this?  My guess would be yes, since
  374. >>as the OS becomes more robust, things like writing values into
  375. >>code segments and/or executing data segments become verboten.
  376. >
  377. >Copland will support existing xDEFs, so I'd expect these techniques to
  378. >keep working.  The OS will be more robust, but it won't stop you from
  379. >changing the contents of resources in your own heap.  But Copland-savvy
  380. >apps won't use custom xDEFs, they'll override SOM classes, so the
  381. >motivation for stub xDEFs will go away.
  382.  
  383. I guess it's time to start learning a thing or two about SOM.  That is,
  384. if I can ever put down this facinating OLE reading....  (very (:-))
  385.  
  386. >>And, for that matter:
  387. >>
  388. >>(3)  Was this ever a good idea?
  389. >
  390. >I think it was a great idea.  What I'd question is the decision to require
  391. >stand-alone resources for something as simple as drawing list cells.  A
  392. >simple callback would have made everyone's life easier.
  393.  
  394. Quite true, but there are quite a few things about the Mac Toolbox that
  395. leave quite a bit to be desired.  Though it does sound like Apple is
  396. finally starting to correct some of them with Copland.  (See related
  397. thread on Copland robustness.)
  398.  
  399.  
  400.  
  401. +++++++++++++++++++++++++++
  402.  
  403. >From gurgle@apple.com (Pete Gontier)
  404. Date: Tue, 12 Sep 1995 19:05:49 -0800
  405. Organization: Apple Computer, Inc.
  406.  
  407. In article <430943$mdm@dawn.mmm.com>, rdwells@mmm.com (Richard Wells) quoted:
  408.  
  409.  >>> (2)  Will Copland disallow this?  My guess would be yes, since
  410.  >>> as the OS becomes more robust, things like writing values into
  411.  >>> code segments and/or executing data segments become verboten.
  412.  
  413. If you don't like the idea of self-modifying code, use the 10-byte LDEF
  414. trick instead. I believe the instructions go like this:
  415.  
  416.          LEA   @0,A0
  417.          JMP   (A0)
  418.    @0:   DC.L  'hack'
  419.  
  420. Your mileage may vary; I've typed this in from memory.
  421.  
  422. Since the "instruction" at the label never gets executed, you can stash
  423. the real address in there without flushing the instruction cache or
  424. worrying about DTS rousting you out of bed in the middle of the night to
  425. answer for your sins.
  426.  
  427. With respect to Copland issues, I would be very surprised if this broke
  428. under Copland. Consider most present manager APIs to be reasonably stable.
  429. Look for radically new APIs for the Copland-savvy GUI. Well, OK, maybe not
  430. radically new. New. :-) If LDEFs were CFM-based, then there'd be something
  431. to be concerned about, but they aren't, so there isn't.
  432.  
  433. -- 
  434.  Pete Gontier // Software reenignE
  435.  Macintosh Developer Technical Support // Apple Computer, Inc.
  436.  
  437. +++++++++++++++++++++++++++
  438.  
  439. >From david_rehring@gdt.com (David Rehring)
  440. Date: Wed, 13 Sep 1995 11:40:32 -0700
  441. Organization: GDT Softworks, Inc.
  442.  
  443. In article <gurgle-1209951905490001@mac69.kip.apple.com>, gurgle@apple.com
  444. (Pete Gontier) wrote:
  445.  
  446. > In article <430943$mdm@dawn.mmm.com>, rdwells@mmm.com (Richard Wells) quoted:
  447. >  >>> (2)  Will Copland disallow this?  My guess would be yes, since
  448. >  >>> as the OS becomes more robust, things like writing values into
  449. >  >>> code segments and/or executing data segments become verboten.
  450. > If you don't like the idea of self-modifying code, use the 10-byte LDEF
  451. > trick instead. I believe the instructions go like this:
  452. >          LEA   @0,A0
  453. >          JMP   (A0)
  454. >    @0:   DC.L  'hack'
  455. > Your mileage may vary; I've typed this in from memory.
  456. > Since the "instruction" at the label never gets executed, you can stash
  457. > the real address in there without flushing the instruction cache or
  458. > worrying about DTS rousting you out of bed in the middle of the night to
  459. > answer for your sins.
  460. > With respect to Copland issues, I would be very surprised if this broke
  461. > under Copland. Consider most present manager APIs to be reasonably stable.
  462. > Look for radically new APIs for the Copland-savvy GUI. Well, OK, maybe not
  463. > radically new. New. :-) If LDEFs were CFM-based, then there'd be something
  464. > to be concerned about, but they aren't, so there isn't.
  465. > -- 
  466. >  Pete Gontier // Software reenignE
  467. >  Macintosh Developer Technical Support // Apple Computer, Inc.
  468.  
  469.  
  470. But, don't most caches load more memory into them than is actually
  471. required (like each cache area holds 8 or 16 bytes and is loaded and
  472. flushed in one shot).  So, depending on where in memory the instructions
  473. are, the memory just after the JMP(A0) could have been loaded into the
  474. onboard cache and thus would have to be flushed to get the correct value.
  475.  
  476. Of course, this depends on which processor, etc... is currently being used.
  477.  
  478. Or I could be completely wrong (it has happened once or twice, I think)!
  479.  
  480. Later,
  481.  
  482. -- 
  483. David Rehring
  484. Software Engineer
  485. GDT Softworks, Inc.
  486. And all around wacky guy!
  487.  
  488. +++++++++++++++++++++++++++
  489.  
  490. >From owenh@harlequin.com (Owen Hartnett)
  491. Date: Wed, 13 Sep 1995 17:54:37 GMT
  492. Organization: Harlequin, Inc.
  493.  
  494. In article <gurgle-1209951905490001@mac69.kip.apple.com>, gurgle@apple.com
  495. (Pete Gontier) wrote:
  496.  
  497. > In article <430943$mdm@dawn.mmm.com>, rdwells@mmm.com (Richard Wells) quoted:
  498. >  >>> (2)  Will Copland disallow this?  My guess would be yes, since
  499. >  >>> as the OS becomes more robust, things like writing values into
  500. >  >>> code segments and/or executing data segments become verboten.
  501. > If you don't like the idea of self-modifying code, use the 10-byte LDEF
  502. > trick instead. I believe the instructions go like this:
  503. >          LEA   @0,A0
  504. >          JMP   (A0)
  505. >    @0:   DC.L  'hack'
  506. > Your mileage may vary; I've typed this in from memory.
  507. > Since the "instruction" at the label never gets executed, you can stash
  508. > the real address in there without flushing the instruction cache or
  509. > worrying about DTS rousting you out of bed in the middle of the night to
  510. > answer for your sins.
  511.  
  512.  
  513. Except here you have a Mixed Mode context switch if you're on a PowerPC
  514. with native code. (2 switches in fact). You'll want to create a native
  515. version if performance is even slightly an issue for this feature.
  516.  
  517. -Owen
  518.  
  519. +++++++++++++++++++++++++++
  520.  
  521. >From Mark Williams <Mark@streetly.demon.co.uk>
  522. Date: Wed, 13 Sep 95 09:12:01 GMT
  523. Organization: Streetly Software
  524.  
  525.  
  526. In article <gurgle-1209951905490001@mac69.kip.apple.com>, Pete Gontier writes:
  527.  
  528. > In article <430943$mdm@dawn.mmm.com>, rdwells@mmm.com (Richard Wells) quoted:
  529. >  >>> (2)  Will Copland disallow this?  My guess would be yes, since
  530. >  >>> as the OS becomes more robust, things like writing values into
  531. >  >>> code segments and/or executing data segments become verboten.
  532. > If you don't like the idea of self-modifying code, use the 10-byte LDEF
  533. > trick instead. I believe the instructions go like this:
  534. >          LEA   @0,A0
  535. >          JMP   (A0)
  536. >    @0:   DC.L  'hack'
  537. > Your mileage may vary; I've typed this in from memory.
  538. >
  539. > Since the "instruction" at the label never gets executed, you can stash
  540. > the real address in there without flushing the instruction cache or
  541. > worrying about DTS rousting you out of bed in the middle of the night to
  542. > answer for your sins.
  543.  
  544. As posted, the instruction at the label _does_ get executed. You may find MOVE.L        @0,A0 more 
  545. effective than LEA... :-)
  546.  
  547. - --------------------------------------
  548. Mark Williams<Mark@streetly.demon.co.uk>
  549.  
  550. +++++++++++++++++++++++++++
  551.  
  552. >From Matt Slot <fprefect@umich.edu>
  553. Date: 14 Sep 1995 14:53:45 GMT
  554. Organization: University of Michigan
  555.  
  556. Mark Williams, Mark@streetly.demon.co.uk writes:
  557.  > Pete Gontier writes:
  558.  > >          LEA   @0,A0
  559.  > >          JMP   (A0)
  560.  > >    @0:   DC.L  'hack'
  561.  >
  562.  > As posted, the instruction at the label _does_ get executed. You may
  563. find
  564.  > MOVE.L @0,A0 more effective than LEA... :-)
  565.  
  566. Actually that still has the same problem, since the long is part of the
  567. instruction, you will set the address in the data cache, and the wrong 
  568. value will still be in the instruction cache on an '040.
  569.  
  570. MOVE's and LEA's that work on data labels (offsets) work properly. MOVE's
  571. and
  572. LEA'S with immediate parameters are kept fully in the instruction cache
  573. -- and
  574. setting them elsewhere can leave them "stale".
  575.  
  576.  
  577. Pete Gontier then corrects with the right solution:
  578.  >            LEA     @0,A0
  579.  >            MOVE.L  (A0), A0
  580.  >            JMP     (A0)
  581.  >      @0:   DC.L    'hack'
  582.  
  583. (Which reminds me of a mistake I just coded... DOH, thanks!)
  584.  
  585. My preferred way to do xDEF stubs follows:
  586.  
  587.   1) Create a 10 byte stub resource for 68K machines (to paraphrase):
  588.   
  589.              LEA     @0,A0
  590.              MOVE.L  (A0), A0
  591.              JMP     (A0)
  592.        @0:   DC.L    0xDEADBEEF
  593.  
  594.   2) Create a second resource that is simply a PPC routine descriptor 
  595.      with the ProcPtr field empty.
  596.      
  597.   3) Create an "installer" function that loads the proper DefProc resource
  598.      by current ISA and inserts the address of the handler function at the
  599.      right offset. Remember, neither stub has been loaded into the
  600.      instruction cache and that inserting the ProcPtr is just changing a
  601.      data field. You shouldn't have to flush.
  602.      
  603.   4) Let it run... you shouldn't even have to dispose the resource stub, 
  604.      since the proper manager should do it for you. Don't set the resource
  605.      changed flag!
  606.      
  607. I have been using the GENERATINGPOWERPC flag rather than the
  608. GENERATINGCFM 
  609. to conditionally compile the necessary code:
  610.  
  611.  
  612. Handle LoadMDEFStub(MenuDefUPP mdefHandler) {
  613.         Handle mdef;
  614. #if !GENERATINGPOWERPC
  615.         // 68K MDEF stub
  616.         mdef = Get1Resource('MDEF', 98);
  617. #else
  618.         // PPC MDEF stub
  619.         mdef = Get1Resource('MDEF', 99);
  620. #endif
  621.  
  622.         if (! mdef) return(0);
  623.         
  624. #if !GENERATINGPOWERPC
  625.         // Dont quote me on these constants!!!
  626.         BlockMove(&mdefHandler, *mdef + 6, sizeof(mdefHandler));
  627. #else
  628.         BlockMove(&mdefHandler, *mdef + 10, sizeof(mdefHandler));
  629. #endif
  630.  
  631.         return(mdef);
  632.         }
  633. I have used similar techniques for MDEFs, INITs, jGNEFilters, and even a
  634. DRVR (don't ask!).
  635.  
  636. You should know that 68K-CFM will change how code is passed around on the 
  637. 68K platform, and that you should be careful when building stubs for it...
  638. I have no experience with it. Watch the OpenDoc beta-testers... they'll 
  639. find alot of broken software. However, since these techniques don't make  
  640. any assumptions about CFM, just the compiled ISA, they *should* work. 
  641.  
  642. Matt
  643.  
  644. +++++++++++++++++++++++++++
  645.  
  646. >From larson@base.cs.ucla.edu (Christopher Larson)
  647. Date: 14 Sep 1995 16:33:13 GMT
  648. Organization: UCLA, Computer Science Department
  649.  
  650. In article <david_rehring-1309951140330001@204.239.210.210> david_rehring@gdt.com (David Rehring) writes:
  651. >In article <gurgle-1209951905490001@mac69.kip.apple.com>, gurgle@apple.com
  652. >(Pete Gontier) wrote:
  653. >
  654. >> [ snip ]
  655. >> If you don't like the idea of self-modifying code, use the 10-byte LDEF
  656. >> trick instead. I believe the instructions go like this:
  657. >> 
  658. >>          LEA   @0,A0
  659. >>          JMP   (A0)
  660. >>    @0:   DC.L  'hack'
  661. >> 
  662. >> Your mileage may vary; I've typed this in from memory.
  663. >> 
  664. >> Since the "instruction" at the label never gets executed, you can stash
  665. >> the real address in there without flushing the instruction cache or
  666. >> worrying about DTS rousting you out of bed in the middle of the night to
  667. >> answer for your sins.
  668. >
  669. >But, don't most caches load more memory into them than is actually
  670. >required (like each cache area holds 8 or 16 bytes and is loaded and
  671. >flushed in one shot).  So, depending on where in memory the instructions
  672. >are, the memory just after the JMP(A0) could have been loaded into the
  673. >onboard cache and thus would have to be flushed to get the correct value.
  674.  
  675. Let's assume a copy-back data cache and a read-only instruction cache (the
  676. 'worst case' from a self-modifying code point of view). When you write the
  677. jump location into @0, you're writing data (as far as the CPU is concerned),
  678. so the new target address will be in the data cache. If there is a copy
  679. of the code in the instruction cache, that copy remains unmodified. When
  680. the JMP instruction is executed, the instruction itself is read from the
  681. instruction cache, but when the dereference of A0 takes place, as far as
  682. the CPU is concerned, it's reading data. So the copy of whatever is stored
  683. at @0 is read from the data cache, not the instruction cache. Ergo, no
  684. problem with stale data.
  685.  
  686. It's certainly possible for the instruction cache to contain bytes which are
  687. not instructions, as you point out. However, only bytes which are executed as
  688. instructions are read from the instruction cache. So anything that isn't
  689. executed as an instruction is just wasted space in the instruciton cache. If
  690. the caches are unified, then there is no problem at all, unless you're writing
  691. directly into memory from some source which bypasses the cache (like an
  692. expansion card, and this problem would exist as well for separate caches).
  693.  
  694. The moral of the story is that unless you're modifying the instructions
  695. themselves (not happening in this case), or you're writing to memory from
  696. someplace other than the CPU (also not happening in this case), you don't
  697. need to flush the instruction cache.
  698.  
  699. --Chris
  700. _______________________________________________________________________________
  701. Chris Larson -- Amateur Macintosh Geek, CoBase Research Assistant
  702. L.A. Institute of Slowly and Painfully Working Out the Surprisingly Obvious
  703. - -------------------------------------+---------------------------------------
  704. (Insert Disclaimer Here)               | Who's the man ridin' in the sun?
  705. UCLA Bruins--1995 NCAA Men's Basketball| Who's the man with the itchy gun?
  706.              National Champions (yea!) | Who's the man who kills for fun?
  707. Internet: larson@kingston.cs.ucla.edu  | Psycho Dad, Psycho Dad, PSYCHO DAD!
  708.  
  709. +++++++++++++++++++++++++++
  710.  
  711. >From gurgle@apple.com (Pete Gontier)
  712. Date: Thu, 14 Sep 1995 13:15:57 -0800
  713. Organization: Apple Computer, Inc.
  714.  
  715. In article <439lg9$h03@delphi.cs.ucla.edu>,
  716. larson@base.cs.ucla.edu (Christopher Larson) wrote:
  717.  
  718.  > It's certainly possible for the instruction cache to contain bytes which are
  719.  > not instructions, as you point out. However, only bytes which are executed as
  720.  > instructions are read from the instruction cache.
  721.  
  722. Thank you thank you thank you.
  723.  
  724. Sometimes I'm not able to follow every can of worms I open to its logical
  725. conclusion. (Being here isn't really part of my job -- yet.)
  726.  
  727. To reiterate for those who may have missed it, I posted a correction to
  728. the wrong newsgroup recently. Errors compounded with errors. Anyway, here
  729. it is:
  730.  
  731. In article <gurgle-1309950939480001@mac758.kip.apple.com>,
  732. gurgle@apple.com (Pete Gontier) wrote:
  733.  
  734. > Matthias Neeracher pointed out in email the code I posted has a bug. (You
  735. > were warned! :-) Here is a correction:
  736. >
  737. >       LEA     @0,A0     ; point to last long word in code resource
  738. >       MOVE.L  (A0),A0   ; get that last long word
  739. >       JMP     (A0)      ; phone home
  740. > @0:
  741. >       DC.L    'hack'    ; this "instruction" can get stale in the code cache
  742. >                         ; because it will never be executed
  743.  
  744. In article <199509141927261141229@stk.berlin.snafu.de>,
  745. stk@berlin.snafu.de (Stefan Kurth) wrote:
  746.  
  747.  > What's wrong with
  748.  > 
  749.  >         MOVE.L  @0,A0
  750.  >         JMP     (A0)
  751.  > @0:     DC.L    'hack'
  752.  
  753. Nothing's wrong with it. It may even be 10 bytes long as I originally
  754. promised. :-) The point is that neither of our examples require
  755. instruction modification or cache flushing. Memory only becomes code, as
  756. far as the cache is concerned, when it is executed.
  757.  
  758.  > Personally, I'm using
  759.  > 
  760.  >         MOVE.L  @0,-(A7)
  761.  >         RTS
  762.  > @0:     DC.L    'hack'
  763.  
  764. That's even better because it'll work in contexts where you can't afford
  765. to step on a register.
  766.  
  767. -- 
  768.  Pete Gontier // Software reenignE
  769.  Macintosh Developer Technical Support // Apple Computer, Inc.
  770.  
  771. +++++++++++++++++++++++++++
  772.  
  773. >From Mark Williams <Mark@streetly.demon.co.uk>
  774. Date: Fri, 15 Sep 95 13:41:52 GMT
  775. Organization: Streetly Software
  776.  
  777.  
  778. In article <439flp$guq@srvr1.engin.umich.edu>, Matt Slot writes:
  779.  
  780. > Mark Williams, Mark@streetly.demon.co.uk writes:
  781. >  > Pete Gontier writes:
  782. >  > >          LEA   @0,A0
  783. >  > >          JMP   (A0)
  784. >  > >    @0:   DC.L  'hack'
  785. >  >
  786. >  > As posted, the instruction at the label _does_ get executed. You may
  787. > find
  788. >  > MOVE.L @0,A0 more effective than LEA... :-)
  789. > Actually that still has the same problem, since the long is part of the
  790. > instruction, you will set the address in the data cache, and the wrong 
  791. > value will still be in the instruction cache on an '040.
  792.  
  793. Its not quite the same problem... the code as posted just jumped to @0, which is definitely not 
  794. going to work.
  795.  
  796. Now even assuming you are right, the code at @0 cant be in the cache (unless it wasnt flushed when 
  797. the xDEF was loaded... in which case the code wont work anyway), so changing the lea to a move will 
  798. work. You may of course have problems if you keep changing the xDEF to point at different bits of 
  799. code.
  800.  
  801. > MOVE's and LEA's that work on data labels (offsets) work properly. MOVE's
  802. > and
  803. > LEA'S with immediate parameters are kept fully in the instruction cache
  804. > -- and
  805. > setting them elsewhere can leave them "stale".
  806.  
  807. LEA's dont access memory (and hence the cache) at all.
  808.  
  809. Now, according to M68040UM/AD, section 4.7.1, The Instruction Cache:
  810.  
  811. "The IU uses the instruction cache to store instruction prefetches as it requests them. Instruction 
  812. prefetches are normally requested from sequential memory locations except when a change of program 
  813. flow occurs or when an instruction that modifies the SR is executed...."
  814.  
  815. This is the only reference I can find to what goes through the instruction cache (although i havnt 
  816. read the book that thoroughly) and it suggests to me that pc relative reads _dont_ go through the 
  817. instruction cache (but i can see that it would make a lot of sense if they did).
  818.  
  819. Can anyone give a definitive answer to this?
  820.  
  821. On a related note, if you leave the xDEF unlocked between calls, do you need to flush the cache 
  822. whenever you lock it down and call it, or will the memory manager handle that? What about if you 
  823. have DetachResource'd the xDEF?
  824.  
  825. - --------------------------------------
  826. Mark Williams<Mark@streetly.demon.co.uk>
  827.  
  828. +++++++++++++++++++++++++++
  829.  
  830. >From grobbins@znet.com (Grobbins)
  831. Date: Sat, 16 Sep 1995 09:58:38 -0700
  832. Organization: Skunkworks
  833.  
  834. In article <95091513415200188@streetly.demon.co.uk>,
  835. Mark@streetly.demon.co.uk wrote:
  836. >This is the only reference I can find to what goes through the
  837. instruction cache (although i havnt 
  838. >read the book that thoroughly) and it suggests to me that pc relative
  839. reads _dont_ go through the 
  840. >instruction cache (but i can see that it would make a lot of sense if
  841. they did).
  842.  
  843. How close in memory data that gets modified and instructions that get
  844. executed are is irrelevant ('cept for folks writing ROMable code.)  If
  845. it's not an executable instruction that is getting altered (like a JMP
  846. xxxxxxxx) then everything happens on the data side of the 68K cache and no
  847. flushing is needed.  
  848.  
  849. So as Gontier advocates, load the destination into an address register and
  850. jump through that, or push it on the stack and RTS, and you can ignore
  851. cache issues.  Remember that cache flushes are extremely expensive these
  852. days, so avoid them when possible, and use FlushCodeCacheRange for 68K
  853. flushes and MakeDataExecutable for PPC flushes when necessary.
  854.  
  855. >On a related note, if you leave the xDEF unlocked between calls, do you
  856. need to flush the cache 
  857. >whenever you lock it down and call it, or will the memory manager handle
  858. that? What about if you 
  859. >have DetachResource'd the xDEF?
  860.  
  861. For 68K code, the memory manager uses BlockMove to move its blocks, and
  862. BlockMove of more than a small number of bytes flushes the caches for the
  863. appropriate range, so you never have to worry about 68K code resources. 
  864.  
  865. Remember that on PPC machines, the processor caches are irrelevant to 68K
  866. code, since 68K code is data to the processor.  The DR Emulator caches do
  867. need to be flushed like the 68040's caches, however.  BlockMove,
  868. FlushCodeCacheRange, and the other 68K-related cache flushing routines
  869. apply to the DR Emulator but don't have any effect on the PPC processor
  870. caches.
  871.  
  872. Let's talk native code resources now.  For accelerated resources (PPC code
  873. fragments kept in resources) the Code Fragment Manager flushes the code
  874. range when preparing a fragment, and it always prepares resource-based
  875. fragments before entry on 603e/604 machines (the 601 has a unified
  876. data/instruction cache and hence isn't susceptible to problems, and CFM on
  877. old machines only re-prepares resource-based fragments that have moved.)  
  878.  
  879. At least originally, the 603-based Macs (5200 series and similar) weren't
  880. re-preparing accelerated resources if they didn't appear to have moved, so
  881. in rare cases an accelerated resource that moved back to its original
  882. location before being executed a second time might not be consistent in
  883. the 603 instruction cache and could crash.  For that reason, it's a good
  884. idea to always call MakeDataExecutable on an accelerated resource's code
  885. before jumping to it.
  886.  
  887. The system doesn't know about or do anything for native non-CFM code kept
  888. in resources, so always call MakeDataExecutable before jumping to those.
  889.  
  890.  
  891. Grobbins                                     grobbins@znet.com
  892.  
  893. ---------------------------
  894.  
  895. >From rondunn@ibm.net (Ron Dunn)
  896. Subject: Apple Camera API
  897. Date: 15 Sep 1995 14:29:55 GMT
  898. Organization: Systems Renovation P/L
  899.  
  900. I have to come up with an application to be used for gate security at
  901. a freight terminal.  One of the requirements is to store images of
  902. trucks as they enter and leave the terminal.  I <was> planning to
  903. use video tape.
  904.  
  905. I recently saw a demonstration of the Apple Quicktake 950 camera, where
  906. it was connected by a cable to a Power Macintosh.  The demonstrator
  907. clicked the mouse, the camera took a photograph, and it was downloaded
  908. to the software package.
  909.  
  910. This is very similar to my requirement.  Is there an API available
  911. which supports this camera?  If so, I could place numbers of these
  912. around the terminal controlled by my program.  It could take photos at
  913. the appropriate time, download the image, and store it in the
  914. database.
  915.  
  916. Ron.
  917.  
  918. +++++++++++++++++++++++++++
  919.  
  920. >From bc@wetware.com (monsieur HAINEUX)
  921. Date: 15 Sep 1995 17:37:17 GMT
  922. Organization: GRAFIX::CODERRE
  923.  
  924. In article <43c2l3$2rnm@news-s01.ny.us.ibm.net>, rondunn@ibm.net (Ron
  925. Dunn) wrote:
  926.  
  927. |   I have to come up with an application to be used for gate security at
  928. |   a freight terminal.  One of the requirements is to store images of
  929. |   trucks as they enter and leave the terminal.  I <was> planning to
  930. |   use video tape.
  931. |   
  932. |   I recently saw a demonstration of the Apple Quicktake 950 camera, where
  933. |   it was connected by a cable to a Power Macintosh.  The demonstrator
  934. |   clicked the mouse, the camera took a photograph, and it was downloaded
  935. |   to the software package.
  936. |   
  937. |   This is very similar to my requirement.  Is there an API available
  938. |   which supports this camera?  If so, I could place numbers of these
  939. |   around the terminal controlled by my program.  It could take photos at
  940. |   the appropriate time, download the image, and store it in the
  941. |   database.
  942.  
  943. It's the Quicktake 150, and the API documents are available: "Quicktake
  944. Digital Camera Developer Note."
  945.  
  946. Now, I don't exactly know which CD it's on, or where to order it from.
  947.  
  948. +++++++++++++++++++++++++++
  949.  
  950. >From mpeirce@outpost.peircesw.com (Michael Peirce)
  951. Date: Tue, 19 Sep 95 16:07:59 PT
  952. Organization: Peirce Software, Inc.
  953.  
  954.  
  955. In article <bc-1509951037450001@mac877.kip.apple.com> (comp.sys.mac.programmer.help), bc@wetware.com (monsieur HAINEUX) writes:
  956. > In article <43c2l3$2rnm@news-s01.ny.us.ibm.net>, rondunn@ibm.net (Ron
  957. > Dunn) wrote:
  958. > |   I have to come up with an application to be used for gate security at
  959. > |   a freight terminal.  One of the requirements is to store images of
  960. > |   trucks as they enter and leave the terminal.  I <was> planning to
  961. > |   use video tape.
  962. > |   
  963. > |   I recently saw a demonstration of the Apple Quicktake 950 camera, where
  964. > |   it was connected by a cable to a Power Macintosh.  The demonstrator
  965. > |   clicked the mouse, the camera took a photograph, and it was downloaded
  966. > |   to the software package.
  967. > |   
  968. > |   This is very similar to my requirement.  Is there an API available
  969. > |   which supports this camera?  If so, I could place numbers of these
  970. > |   around the terminal controlled by my program.  It could take photos at
  971. > |   the appropriate time, download the image, and store it in the
  972. > |   database.
  973. > It's the Quicktake 150, and the API documents are available: "Quicktake
  974. > Digital Camera Developer Note."
  975. > Now, I don't exactly know which CD it's on, or where to order it from.
  976.  
  977. I've seen this API on the latest MacOS SDK.  You can control just
  978. about every aspect of this camera using the API.
  979.  
  980. Anyone have a QuickTake hooked up the the web?  It seems this would
  981. be a better solution to net cams than video cameras...   hmmm.... :-)
  982.  
  983. --
  984. Michael Peirce           mpeirce@peircesw.com
  985. Peirce Software Inc.     719 Hibiscus Place, San Jose California 95117 USA
  986.                          voice: +1 408 244 6554,      fax: +1 408 244 6882
  987.  
  988. Makers of Peirce Print Tools, Smoothie, AppSizer, DeskPicture, & ShareDraw
  989.  
  990. <ftp://mirrors.aol.com/pub/info-mac/cfg/app-sizer-22.hqx>
  991. <ftp://mirrors.aol.com/pub/info-mac/gui/desk-picture-401.hqx>
  992. <ftp://mirrors.aol.com/pub/info-mac/gst/grf/share-draw-20.hqx>
  993.  
  994. +++++++++++++++++++++++++++
  995.  
  996. >From Binky the Wonderwhorse <binky@mmcorp.com>
  997. Date: 20 Sep 1995 16:45:08 GMT
  998. Organization: MultiMedia Corporation
  999.  
  1000. lo,
  1001.  
  1002. Well I haven't had any experience of programmming for the QuickTake yet
  1003. but I have written vidcam code that grabs images and delivers them on the
  1004. web.  I've been successful at doing this (live web video).
  1005.  
  1006. "It seems this would be a better solution to net cams than video cameras"
  1007.  
  1008. Bollox, works for me just fine.
  1009.  
  1010. Binky
  1011.  
  1012. +++++++++++++++++++++++++++
  1013.  
  1014. >From mpeirce@outpost.peircesw.com (Michael Peirce)
  1015. Date: Wed, 20 Sep 95 21:00:41 PT
  1016. Organization: Peirce Software, Inc.
  1017.  
  1018.  
  1019. In article <43pgek$4vi@news.bt.net> (comp.sys.mac.programmer.help), Binky the Wonderwhorse <binky@mmcorp.com> writes:
  1020. > lo,
  1021. > Well I haven't had any experience of programmming for the QuickTake yet
  1022. > but I have written vidcam code that grabs images and delivers them on the
  1023. > web.  I've been successful at doing this (live web video).
  1024. > "It seems this would be a better solution to net cams than video cameras"
  1025. > Bollox, works for me just fine.
  1026.  
  1027. What I mean is cheaper.  You can pick up QuickTake 100's cheap - and
  1028. there is no need for a digitizer card.  The API is easy to deal with
  1029. too.
  1030.  
  1031. --
  1032. Michael Peirce           mpeirce@peircesw.com
  1033. Peirce Software Inc.     719 Hibiscus Place, San Jose California 95117 USA
  1034.                          voice: +1 408 244 6554,      fax: +1 408 244 6882
  1035.  
  1036. Makers of Peirce Print Tools, Smoothie, AppSizer, DeskPicture, & ShareDraw
  1037.  
  1038. <ftp://mirrors.aol.com/pub/info-mac/cfg/app-sizer-22.hqx>
  1039. <ftp://mirrors.aol.com/pub/info-mac/gui/desk-picture-401.hqx>
  1040. <ftp://mirrors.aol.com/pub/info-mac/gst/grf/share-draw-20.hqx>
  1041.  
  1042. +++++++++++++++++++++++++++
  1043.  
  1044. >From sproul@eos.ap.org (Mark Sproul)
  1045. Date: Wed, 20 Sep 1995 11:48:43 -0400
  1046. Organization: Associated Press R&D
  1047.  
  1048. In article <43c2l3$2rnm@news-s01.ny.us.ibm.net>, rondunn@ibm.net (Ron
  1049. Dunn) wrote:
  1050.  
  1051.  
  1052. > Itrucks as they enter and leave the terminal.  I <was> planning to
  1053.  recently saw a demonstration of the Apple Quicktake 950 camera, where
  1054. > it was connected by a cable to a Power Macintosh.  The demonstrator
  1055. > clicked the mouse, the camera took a photograph, and it was downloaded
  1056. > to the software package.
  1057.  
  1058.  
  1059. Its a QuickTake 150, I have written software to drive it, its not hard,
  1060.  
  1061.  
  1062.  
  1063. Check out my web page at
  1064.  
  1065.  
  1066. http://pilot.njin.net/~msproul/macintosh/imaging.html
  1067.  
  1068. The API is avaialbe from APDA and is on the MacOS sdk CD-ROMs.
  1069.  
  1070. Mark
  1071.  
  1072. ---------------------------
  1073.  
  1074. >From st93urnu@post.drexel.edu (Aaron D. Marasco)
  1075. Subject: AppleScript recursiveness
  1076. Date: Wed, 13 Sep 1995 19:15:29 -0400
  1077. Organization: Drexel University
  1078.  
  1079. Hi! I would like to know if anyone has any ideas/experience in recursing
  1080. (sp?) the directory structure of a drive... I'd basically like to get a
  1081. list of all the folders in an entire drive, similar to MSDOS "/S"
  1082. parameters... Any ideas on how this can be done?
  1083.  
  1084. Thanx in advance...
  1085.  
  1086. -ADM
  1087.  
  1088. +++++++++++++++++++++++++++
  1089.  
  1090. >From plsuh@econ.sas.upenn.edu (Paul L. Suh)
  1091. Date: Wed, 13 Sep 1995 23:26:28 -0400
  1092. Organization: UPenn Grad Econ
  1093.  
  1094. In article <st93urnu-1309951915290001@sn208014.resnet.drexel.edu>,
  1095. st93urnu@post.drexel.edu (Aaron D. Marasco) wrote:
  1096.  
  1097. >Hi! I would like to know if anyone has any ideas/experience in recursing
  1098. >(sp?) the directory structure of a drive... I'd basically like to get a
  1099. >list of all the folders in an entire drive, similar to MSDOS "/S"
  1100. >parameters... Any ideas on how this can be done?
  1101.  
  1102. Easy enough... There's a Walk Folders command, part of the Jon's Commands
  1103. OSAX.  Alternatively, you can code it in AppleScript by using the
  1104. Scriptable Finder.  Recursion works just fine, although you may want to
  1105. increase the script's memory partition if you're using it on a large
  1106. disk.  The following is not debugged, but something like it should work: 
  1107.  
  1108.  
  1109. getSubFolders( choose folder )
  1110.  
  1111. on getSubFolders( folderToScan )
  1112.  
  1113.     tell app "Finder" to set foo to all items in folderToScan whose kind
  1114. is "folder"
  1115.  
  1116.     set subFolders to {}
  1117.     repeat with oneFolder in foo
  1118.         set end of subFolders to getSubFolders(oneFolder)
  1119.     end repeat
  1120.  
  1121.     return foo & subFolders
  1122.  
  1123. end getSubFolders
  1124.  
  1125. Be careful of the line wraps that Newswatcher throws in if you use this. 
  1126. I think the OSAX version is preferable, if only because it's _much_
  1127. faster.  
  1128.  
  1129. Hope this helps.  
  1130.  
  1131.  
  1132. --Paul
  1133.  
  1134. -- 
  1135. P |\   / S   University of Pennsylvania     /---------\
  1136.   | \ /      Graduate Economics             |/-------\|
  1137.   |  X                                      ||  . .  ||  My first Macintosh
  1138.   | / \      Paul L. Suh                    ||  \_/  ||  512K!
  1139.   |/   \ D   plsuh@econ.sas.upenn.edu       ||       ||
  1140.   +------ Q                                 |\-------/|
  1141.                                             |---------|
  1142.                                             |_________|
  1143.  
  1144. +++++++++++++++++++++++++++
  1145.  
  1146. >From Douglas_Shearer@brown.edu (Andrew Shearer)
  1147. Date: 19 Sep 1995 01:46:04 GMT
  1148. Organization: Rhode Island Hospital
  1149.  
  1150. In article <st93urnu-1309951915290001@sn208014.resnet.drexel.edu>,
  1151. st93urnu@post.drexel.edu (Aaron D. Marasco) wrote:
  1152.  
  1153. > Hi! I would like to know if anyone has any ideas/experience in recursing
  1154. > (sp?) the directory structure of a drive... I'd basically like to get a
  1155. > list of all the folders in an entire drive, similar to MSDOS "/S"
  1156. > parameters... Any ideas on how this can be done?
  1157.  
  1158. You could try something like:
  1159.  
  1160. tell application "Finder"
  1161.    get every folder of entire contents of startup disk
  1162. end tell
  1163.  
  1164. or:
  1165.  
  1166. tell application "Finder"
  1167.    get name of every folder of entire contents of startup disk
  1168. end tell
  1169.  
  1170. -- 
  1171. Andrew Shearer
  1172. Regular email: ashearer@mail.rihosp.edu
  1173.  
  1174. ---------------------------
  1175.  
  1176. >From parsoj2@rembrandt.its.rpi.edu (Jeremy Thomas Parsons)
  1177. Subject: Code to copy files?
  1178. Date: 11 Sep 1995 12:32:03 GMT
  1179. Organization: Rensselaer Polytechnic Institute
  1180.  
  1181. I need some example code on how to go about copying a file.
  1182. I've looked about some, but not found anything, except a little
  1183. bit which indicated that it was tricker then it already looked.
  1184.  
  1185. (While I'm at it, an example thermometer or thermoter cdef would
  1186. go wonderful with the above as the files I'm looking to copy are
  1187. huge)
  1188.  
  1189. -Br'fin
  1190.  
  1191.  
  1192.  
  1193. +++++++++++++++++++++++++++
  1194.  
  1195. >From pandhphot@aol.com (PandH Phot)
  1196. Date: 12 Sep 1995 16:55:53 -0400
  1197. Organization: America Online, Inc. (1-800-827-6364)
  1198.  
  1199. I had the same problem. I was thrilled to find some useful sample code in
  1200. Knaster & Rollins' "Macintosh Programming Secrets", 2nd Ed., Chapter 8.
  1201. The basic idea is:
  1202.  
  1203. Open DF
  1204. Get EOF for DF
  1205. Copy data in buffer size of your choice until EOF
  1206. Close DF
  1207.  
  1208. Open RF
  1209. Get EOF of RF
  1210. Copy data in buffer until EOF
  1211. Close RF
  1212.  
  1213. Get file catalog data from original file
  1214. Replace catalog data to destination file.
  1215.  
  1216. Works great!
  1217. Paul
  1218.  
  1219. +++++++++++++++++++++++++++
  1220.  
  1221. >From ari@shore.net (Ari Halberstadt)
  1222. Date: Tue, 12 Sep 1995 21:34:23 -0400
  1223. Organization: North Shore Access/Eco Software, Inc; (info@shore.net)
  1224.  
  1225. In article <431a84$9b@usenet.rpi.edu>, jeremy@hp1.ep.cursci.com wrote:
  1226.  
  1227. >I need some example code on how to go about copying a file.
  1228. >I've looked about some, but not found anything, except a little
  1229. >bit which indicated that it was tricker then it already looked.
  1230.  
  1231. It is trickier. Don't bother thinking about it or trying to do it yourself
  1232. (I tried and I lost :-). Just go over to Apple's ftp site and grab
  1233. MoreFiles.
  1234.  
  1235. >(While I'm at it, an example thermometer or thermoter cdef would
  1236. >go wonderful with the above as the files I'm looking to copy are
  1237. >huge)
  1238.  
  1239. Jim's CDEFs includes a nice thermometer CDEF, among other fun things. You
  1240. can find it at info-mac mirrors.
  1241.  
  1242. -- Ari Halberstadt (ari@shore.net, ari@world.std.com)
  1243.  
  1244. +++++++++++++++++++++++++++
  1245.  
  1246. >From Stefan_Buchholtz@midgard.fido.de (Stefan Buchholtz)
  1247. Date: Wed, 13 Sep 1995 10:45:56 +0200
  1248. Organization: Fido.DE domain gateway (IN e.V.)
  1249.  
  1250. Am 11 Sep 95 schrieb  jeremy an  All:
  1251.  j> I need some example code on how to go about copying a file. I've
  1252.  j> looked about some, but not found anything, except a little bit which
  1253.  j> indicated that it was tricker then it already looked.
  1254.  
  1255. This is basically not too difficult - the following code does the trick, but
  1256. you can probably do a lot better. Some drawbacks: 
  1257. - the file dates (creation & last modification date) are not set. This should
  1258. be easy to implement.
  1259. - The routine never calls WaitNextEvent, so all other processes are halted
  1260. during the copy. This is evil and should never be done in a real application.
  1261. - It has no progress indicator.
  1262. - Maybe it could be made faster by using lowlevel calls in asynchronous mode.
  1263. Especially when running SCSI Manager 4.3 and later.
  1264.  
  1265. OSErr CopyFile(FSSpecPtr spec, FSSpecPtr destDir)
  1266. {
  1267.     short       readRefNum,
  1268.                 writeRefNum;
  1269.     Ptr         buf;
  1270.     long        count,
  1271.                 bufSize;
  1272.     OSErr       err;
  1273.     Str255      name;
  1274.     FSSpec      destFile;
  1275.     Boolean     eofReached;
  1276.     HFileParam  pb;
  1277.     
  1278.     pb.ioCompletion = NULL;
  1279.     pb.ioVRefNum = spec->vRefNum;
  1280.     pb.ioFVersNum = 0;
  1281.     pb.ioFDirIndex = 0;
  1282.     pb.ioDirID = spec->parID;
  1283.     pStringCopy(spec->name, name);
  1284.     pb.ioNamePtr = name;
  1285.     err = PBHGetFInfo((HParmBlkPtr)&pb, false);
  1286.     if (err)
  1287.         return err;
  1288.     err = FSpOpenDF(spec, fsRdPerm, &readRefNum);
  1289.     if (err)
  1290.         return err;
  1291.     *name = 1;
  1292.     name[1] = ':';
  1293.     ConcatString(name, destDir->name);
  1294.     name[++*name] = ':';
  1295.     ConcatString(name, spec->name);
  1296.     err = FSMakeFSSpec(destDir->vRefNum, destDir->parID, name, &destFile);
  1297.     if (err == noErr) {
  1298.         err = FSpDelete(&destFile);
  1299.         if (err) {
  1300.             FSClose(readRefNum);
  1301.             return err;
  1302.         }
  1303.     }
  1304.     err = FSpCreate(&destFile, pb.ioFlFndrInfo.fdCreator,
  1305.                     pb.ioFlFndrInfo.fdType, smSystemScript);
  1306.     if (err) {
  1307.         FSClose(readRefNum);
  1308.         return err;
  1309.     }
  1310.     err = FSpOpenDF(&destFile, fsRdWrPerm, &writeRefNum);
  1311.     if (err) {
  1312.         FSClose(readRefNum);
  1313.         FSpDelete(&destFile);
  1314.         return err;
  1315.     }
  1316.     bufSize = (MaxBlock() / 4096) * 4096 - 8192;
  1317.     buf = NewPtr(bufSize);
  1318.     eofReached = false;
  1319.     while (!eofReached) {
  1320.         count = bufSize;
  1321.         err = FSRead(readRefNum, &count, buf);
  1322.         if (err && err != eofErr) {
  1323.             DisposePtr(buf);
  1324.             FSClose(readRefNum);
  1325.             FSClose(writeRefNum);
  1326.             FSpDelete(&destFile);
  1327.             return err;
  1328.         } else if (err == eofErr)
  1329.             eofReached = true;
  1330.         err = FSWrite(writeRefNum, &count, buf);
  1331.         if (err) {
  1332.             DisposePtr(buf);
  1333.             FSClose(readRefNum);
  1334.             FSClose(writeRefNum);
  1335.             FSpDelete(&destFile);
  1336.             return err;
  1337.         }
  1338.     }
  1339.     FSClose(readRefNum);
  1340.     FSClose(writeRefNum);
  1341.     
  1342.     if (pb.ioFlRLgLen > 0) {            // Resource Fork
  1343.         err = FSpOpenRF(spec, fsRdPerm, &readRefNum);
  1344.         if (err) {
  1345.             DisposePtr(buf);
  1346.             return err;
  1347.         }
  1348.         FSpCreateResFile(&destFile, pb.ioFlFndrInfo.fdCreator,
  1349.                          pb.ioFlFndrInfo.fdType, smSystemScript);
  1350.         if (err = ResError()) {
  1351.             DisposePtr(buf);
  1352.             FSClose(readRefNum);
  1353.             return err;
  1354.         }
  1355.         err = FSpOpenRF(&destFile, fsRdWrPerm, &writeRefNum);
  1356.         if (err) {
  1357.             DisposePtr(buf);
  1358.             FSClose(readRefNum);
  1359.             return err;
  1360.         }
  1361.         eofReached = false;
  1362.         while (!eofReached) {
  1363.             count = bufSize;
  1364.             err = FSRead(readRefNum, &count, buf);
  1365.             if (err && err != eofErr) {
  1366.                 DisposePtr(buf);
  1367.                 FSClose(readRefNum);
  1368.                 FSClose(writeRefNum);
  1369.                 return err;
  1370.             } else if (err == eofErr)
  1371.                 eofReached = true;
  1372.             err = FSWrite(writeRefNum, &count, buf);
  1373.             if (err) {
  1374.                 DisposePtr(buf);
  1375.                 FSClose(readRefNum);
  1376.                 FSClose(writeRefNum);
  1377.                 return err;
  1378.             }
  1379.         }
  1380.         FSClose(readRefNum);
  1381.         FSClose(writeRefNum);
  1382.     }
  1383.     DisposePtr(buf);
  1384. }
  1385.  
  1386. Und tschuess...
  1387.     Stefan
  1388.  
  1389. +++++++++++++++++++++++++++
  1390.  
  1391. >From peter@stairways.com.au (Peter N Lewis)
  1392. Date: Fri, 15 Sep 1995 00:34:34 +0800
  1393. Organization: Stairways Software
  1394.  
  1395. In article <434s4p$orj@newsbf02.news.aol.com>, pandhphot@aol.com (PandH
  1396. Phot) wrote:
  1397.  
  1398. >I had the same problem. I was thrilled to find some useful sample code in
  1399. >Knaster & Rollins' "Macintosh Programming Secrets", 2nd Ed., Chapter 8.
  1400. >The basic idea is:
  1401.  
  1402. Copying a file is impossible to do right.
  1403.  
  1404. First off, you need to make sure that you don't set the type and creator
  1405. to anything useful until you've finished copying it (assuming you intend
  1406. to give time while copying it), since then the user might double click a
  1407. half copying application/document for example.  So you need to set the
  1408. type/creator to something silly first, and then correct it after you copy
  1409. the file.
  1410.  
  1411. Next, you have to remember that if the destination is in a drop folder,
  1412. then you can't set the type/creator after either fork has any data in it.
  1413. , So the type and creator have to be set first.  Hmm, well, there's
  1414. contradiction number one.
  1415.  
  1416. And of course, you have to set the catalog info at the end, so you can set
  1417. the correct modification date (copying a file does not modify it).  Ooops,
  1418. contradiction number two.
  1419.  
  1420. Don't forget to touch the parent directory as well.
  1421.  
  1422. I suggest using MoreFiles - not that I do that myself, but it's a good
  1423. idea anyway.
  1424.  
  1425. Enjoy,
  1426.    Peter.
  1427. -- 
  1428. "there is no significant correlation to violence on TV and agression in 
  1429. daily life" - NHR Broadcasting Culture Research Institute in Tokyo.
  1430.  
  1431. +++++++++++++++++++++++++++
  1432.  
  1433. >From parsoj2@rembrandt.its.rpi.edu (Jeremy Thomas Parsons)
  1434. Date: 16 Sep 1995 03:46:11 GMT
  1435. Organization: Rensselaer Polytechnic Institute
  1436.  
  1437. In article <peter-1509950034340001@zany.peter.com.au>,
  1438. Peter N Lewis <peter@stairways.com.au> wrote:
  1439. >I suggest using MoreFiles - not that I do that myself, but it's a good
  1440. >idea anyway.
  1441. >
  1442. >Enjoy,
  1443. >   Peter.
  1444. >-- 
  1445. >"there is no significant correlation to violence on TV and agression in 
  1446. >daily life" - NHR Broadcasting Culture Research Institute in Tokyo.
  1447.  
  1448. May I ask as to what MoreFiles is and a full URL to find it?
  1449. It's been mentioned a few times before, and hinted that it was on one of
  1450. Apple's sites. However, I've spent some time hunting around www.info.apple.com
  1451. and have yet to even see anything ...
  1452.  
  1453. It has my interest, but I just can't find it...
  1454. Thanks in advance.
  1455. Br'fin
  1456.  
  1457.  
  1458.  
  1459. +++++++++++++++++++++++++++
  1460.  
  1461. >From tim@dierks.org (Tim Dierks)
  1462. Date: Sat, 16 Sep 1995 13:35:00 +0100
  1463. Organization: Best Internet Communications
  1464.  
  1465. In article <43dha3$q8l@usenet.rpi.edu>, parsoj2@rembrandt.its.rpi.edu
  1466. (Jeremy Thomas Parsons) wrote:
  1467.  
  1468. >In article <peter-1509950034340001@zany.peter.com.au>,
  1469. >Peter N Lewis <peter@stairways.com.au> wrote:
  1470. >>I suggest using MoreFiles - not that I do that myself, but it's a good
  1471. >>idea anyway.
  1472. >May I ask as to what MoreFiles is and a full URL to find it?
  1473.  
  1474. MoreFiles is Jim Luther's excellent file manager library which offers a
  1475. number of utility routines to do things you need to do but which are hard
  1476. to write. Everyone should have it.
  1477.  
  1478. <ftp://ftp.info.apple.com/Apple.Support.Area/Developer_Services/Sample_Code/MoreFiles_1.3.1/>
  1479.  
  1480. Enjoy,
  1481.  - Tim
  1482.  
  1483. -- 
  1484. Tim Dierks
  1485. tim@dierks.org
  1486.  
  1487. ---------------------------
  1488.  
  1489. >From Darren Giles <mars@netcom.com>
  1490. Subject: Debugging tips?  Here's one!
  1491. Date: Tue, 19 Sep 1995 00:08:46 GMT
  1492. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  1493.  
  1494. Always on the lookout for useful debugging tools & tips, I'd love to share
  1495. ideas with others on the topic.  I'll start out by offering a snippet I've
  1496. found very useful -- hopefully others will do the same.
  1497.  
  1498. One thing that's really bugged me about MacsBug on PPC is that the stack
  1499. crawl has become a much less useful tool.  The snippet below gives you
  1500. the ability to keep track of a list of the last significant points your
  1501. program has visited.  It's a list, not a stack, so you can also see
  1502. patterns
  1503. of execution.
  1504.  
  1505. Hardly rocket science, but useful & easy to add.  Just call
  1506. DEBUG_STUFF_INIT
  1507. at startup, then insert a DEBUG_ENTRY wherever you want.  To see what's
  1508. up, especially during a bad hang, just dm [the address that
  1509. DEBUG_STUFF_INIT
  1510. dumped out at startup.]
  1511.  
  1512. The conditional compilation means that if you turn of debugging in your
  1513. final build, the release version of the program won't have any of this
  1514. code in it.
  1515.  
  1516.  
  1517. [debugstuff.h]
  1518. #define DB_ROUTINES_NBR_ENTRIES 40
  1519. #define DB_ROUTINES_CHARS               16
  1520. typedef char                    db_routine_entry[DB_ROUTINES_CHARS];
  1521. #if DEBUGGING
  1522. void DEBUG_ENTRY (char *txt);
  1523. void DEBUG_STUFF_INIT (char *title);
  1524. #else
  1525. #define DEBUG_ENTRY
  1526. #define DEBUG_STUFF_INIT
  1527. #endif
  1528.  
  1529.  
  1530. [debugstuff.c]
  1531. ///////////////////////////////////////////////////////////////////////
  1532. ////
  1533. #if DEBUGGING
  1534. void DEBUG_STUFF_INIT (char *title) {
  1535.         OSErr                   myErr;
  1536.         char                    txt[256];
  1537.         long                    response;
  1538.         
  1539.         
  1540.         if (!MacsBugInstalled()) {
  1541.                 hi_notify ("MacsBug is not installed… the debugging log will be
  1542. inaccessible.");
  1543.         }
  1544.         
  1545.         g_debug_entries= (db_routine_entry*) NewPtrClear
  1546. ((DB_ROUTINES_NBR_ENTRIES+2) * DB_ROUTINES_CHARS);
  1547.         memset (&g_debug_entries[0], '=', DB_ROUTINES_CHARS);
  1548.         BlockMoveData (title, &g_debug_entries[0], strlen(title));
  1549.         memset (&g_debug_entries[DB_ROUTINES_NBR_ENTRIES+1], '=',
  1550. DB_ROUTINES_CHARS);
  1551.         sprintf (txt, "Debugging routine list is at 0x%lx;g", (long)
  1552. g_debug_entries);
  1553.         c2pstr (txt);
  1554.         DebugStr (txt);
  1555. }
  1556. #endif
  1557.  
  1558.  
  1559. ///////////////////////////////////////////////////////////////////////
  1560. ////
  1561. //      This leaves a line in the debugging entry log.
  1562. //      For example, important enter/exit points of routines
  1563. ///////////////////////////////////////////////////////////////////////
  1564. ////
  1565. #if DEBUGGING
  1566. void DEBUG_ENTRY (char *txt) {
  1567.         short                   len;
  1568.         
  1569.         
  1570.         //      Move the previous entries down one
  1571.         BlockMoveData (&g_debug_entries[1], &g_debug_entries[2], 
  1572.                         (DB_ROUTINES_NBR_ENTRIES-1) * DB_ROUTINES_CHARS);
  1573.         
  1574.         //      Clear the new space
  1575.         memset (&g_debug_entries[1], 0, DB_ROUTINES_CHARS);
  1576.         
  1577.         //      Copy in the new entry
  1578.         len= strlen (txt);
  1579.         if (len > DB_ROUTINES_CHARS) {
  1580.                 len= DB_ROUTINES_CHARS;
  1581.         }
  1582.         BlockMoveData (txt, &g_debug_entries[1], len);
  1583. }
  1584. #endif
  1585.  
  1586.  
  1587. Hope this does someone some good.
  1588.  
  1589. - Darren
  1590.  
  1591. ==========================================================================
  1592. Darren Giles, Technical Director                        Terran Interactive
  1593. For info on Cleaner QuickTime compression, visit http://www.terran-int.com
  1594.  
  1595. +++++++++++++++++++++++++++
  1596.  
  1597. >From crawford@scipp.ucsc.edu (Mike Crawford)
  1598. Date: 19 Sep 1995 02:06:39 GMT
  1599. Organization: UC Santa Cruz - SCIPP
  1600.  
  1601. In article <marsDF4LqM.GIy@netcom.com>, Darren Giles  <mars@netcom.com> wrote:
  1602. >Always on the lookout for useful debugging tools & tips, I'd love to share
  1603. >ideas with others on the topic.  I'll start out by offering a snippet I've
  1604. >found very useful -- hopefully others will do the same.
  1605.  
  1606. I've just started writing a Web page on debugging tips.  I'm hoping to
  1607. compile most of it either by having people sending me stuff, or by linking
  1608. to _your_ debugging pages.
  1609.  
  1610. Here's the URL if you want to look at the one tip I have:
  1611.  
  1612. http://www.scruznet.com/~crawford/Computers/macsbug.html
  1613.  
  1614. Some code just like Darren's that I wrote a few years ago allowed me
  1615. to find some bugs in a real-time networking test tool.  The problem
  1616. was that dropping into the debugger would screw up the two-way
  1617. communication.  Instead I ran a recorder, and would add recorder calls
  1618. as I narrowed the bug down.
  1619. -- 
  1620. Mike Crawford                      One in forty Americans believe that they 
  1621. crawford@scruznet.com              have been abducted by aliens.
  1622. crawford@maxwell.ucsc.edu          <-- Finger Me here for PGP Public Key
  1623. http://www.scruznet.com/~crawford/ (under construction; foundation poured.)
  1624.  
  1625. +++++++++++++++++++++++++++
  1626.  
  1627. >From pchang@csd-d-1.Stanford.EDU (The Weasel)
  1628. Date: 19 Sep 1995 05:45:47 GMT
  1629. Organization: Computer Science Department, Stanford University, CA USA.
  1630.  
  1631. In article <43l8jf$fmv@darkstar.ucsc.edu>,
  1632. Mike Crawford <crawford@scipp.ucsc.edu> wrote:
  1633. > Some code just like Darren's that I wrote a few years ago allowed me
  1634. > to find some bugs in a real-time networking test tool.  The problem
  1635. > was that dropping into the debugger would screw up the two-way
  1636. > communication.  Instead I ran a recorder, and would add recorder calls
  1637. > as I narrowed the bug down.
  1638.  
  1639. I recently had an experince like this too where stopping in the
  1640. debugger was just not possible or practical. Normal logging solutions
  1641. would not work since every crash caused a complete machine lock-up.
  1642. The solution, log to the ram disk buffer which is persisten across
  1643. warm boots. 
  1644.  
  1645. Skanky, but effective.
  1646.  
  1647. Peter
  1648.  
  1649. +++++++++++++++++++++++++++
  1650.  
  1651. >From grobbins@znet.com (Grobbins)
  1652. Date: Tue, 19 Sep 1995 00:25:14 -0700
  1653. Organization: Skunkworks
  1654.  
  1655. In article <marsDF4LqM.GIy@netcom.com>, Darren Giles <mars@netcom.com> wrote:
  1656. >One thing that's really bugged me about MacsBug on PPC is that the stack
  1657. >crawl has become a much less useful tool.
  1658.  
  1659. Really?  MacsBug 6.5.2 gives quite useful stack crawls on Power Macs. 
  1660. Combined with such recently-improved commands as wh <address>  ("where is
  1661. this") and a slew of other enhancements added in the last year, MacsBug
  1662. skills are more useful than ever before.
  1663.  
  1664. Grobbins                                        grobbins@znet.com
  1665.  
  1666. +++++++++++++++++++++++++++
  1667.  
  1668. >From dstone@chem.utoronto.ca (David Stone)
  1669. Date: Tue, 19 Sep 1995 17:38:01 GMT
  1670. Organization: University of Toronto Chemistry
  1671.  
  1672. In article <marsDF4LqM.GIy@netcom.com>, Darren Giles <mars@netcom.com>
  1673. wrote:
  1674. > Always on the lookout for useful debugging tools & tips, I'd love to share
  1675. > ideas with others on the topic.  I'll start out by offering a snippet I've
  1676. > found very useful -- hopefully others will do the same.
  1677. > One thing that's really bugged me about MacsBug on PPC is that the stack
  1678. > crawl has become a much less useful tool.  The snippet below gives you
  1679. > the ability to keep track of a list of the last significant points your
  1680. > program has visited.  It's a list, not a stack, so you can also see
  1681. > patterns
  1682. > of execution.
  1683. > Hardly rocket science, but useful & easy to add.  Just call
  1684. > DEBUG_STUFF_INIT
  1685. > at startup, then insert a DEBUG_ENTRY wherever you want.  To see what's
  1686. > up, especially during a bad hang, just dm [the address that
  1687. > DEBUG_STUFF_INIT
  1688. > dumped out at startup.]
  1689. > The conditional compilation means that if you turn of debugging in your
  1690. > final build, the release version of the program won't have any of this
  1691. > code in it.
  1692.  
  1693. I've also used conditional compilation to debug serial communications
  1694. stuff being processed at interrupt time - something like
  1695.  
  1696. #ifdef DEBUG_MY_ROUTINE
  1697.  #define MAX_BUFFER  10000
  1698.         char bufffer[MAX_BUFFER];               //      or NewPtr it or something
  1699.  long bufCount = 0L;
  1700. #endif
  1701. .
  1702. .
  1703. .
  1704. #ifdef DEBUG_MY_ROUTINE
  1705.         if(bufCount <  MAX_BUFFER) {
  1706.                 bufCount ++;
  1707.         buffer[bufCount] = ch;                  //      ch is a character read/written through serial
  1708. port
  1709.         }
  1710. #endif
  1711.  
  1712. etc.  Handy, because you can let it rip for a while to see if there is
  1713. a consistent pattern in the errors in ch - in my case, a stream of Midi
  1714. data through a very basic freeware Midi Driver
  1715.  
  1716. Dave Stone
  1717.  
  1718. +++++++++++++++++++++++++++
  1719.  
  1720. >From Matt Slot <fprefect@umich.edu>
  1721. Date: 20 Sep 1995 01:41:53 GMT
  1722. Organization: University of Michigan
  1723.  
  1724. Darren Giles, mars@netcom.com writes:
  1725.  > One thing that's really bugged me about MacsBug on PPC is that the
  1726. stack
  1727.  > crawl has become a much less useful tool.  The snippet below gives you
  1728.  > the ability to keep track of a list of the last significant points your
  1729.  > program has visited.  It's a list, not a stack, so you can also see
  1730.  > patterns of execution.
  1731.  
  1732. One feature of MacsBug that I like is the "swap" command, which lets you
  1733. leave a second monitor in the debugger (and punches it out of the
  1734. desktop).
  1735. Then, if each DebugStr() ends in ";g"  you will get an onscreen log of the
  1736. last 10 or 15 breaks. I used this to track an elusive bug that would
  1737. freeze
  1738. my Mac and trash Macsbug memory... I could see which breakpoint went last.
  1739.  
  1740. Matt
  1741.  
  1742. +++++++++++++++++++++++++++
  1743.  
  1744. >From dfleck@wacom.com (Dave Fleck)
  1745. Date: Wed, 20 Sep 1995 09:59:15 -0800
  1746. Organization: Wacom Technology Corp.
  1747.  
  1748. Here's my debugging tip.
  1749.  
  1750. I do drivers, and you just plain can't set a breakpoint in ADB completion
  1751. routines (freezes the keyboard so MacsBug is worthless!).
  1752.  
  1753. So I throw one of the routines below into the routine to see when a piece
  1754. of code gets executed.
  1755.  
  1756. What does it do? It "lights up" a bar (length dependant on screen
  1757. resolution) in the menu bar. So if you DotToggle(300); you get a flashing
  1758. short line in the menu bar.
  1759.  
  1760.  
  1761. void DotOn(long where) {
  1762.    long  *dot;
  1763.    dot = (long *)(LMGetScrnBase() + where);
  1764.    *dot |= -1;
  1765. }
  1766. void DotOff(long where) {
  1767.    long  *dot;
  1768.    dot = (long *)(LMGetScrnBase() + where);
  1769.    *dot &= 0;
  1770. }
  1771. void DotToggle(long where) {
  1772.    long  *dot;
  1773.    dot = (long *)(LMGetScrnBase() + where);
  1774.    *dot ^= -1;
  1775. }
  1776.  
  1777. dave
  1778. - ---------------------------------------------------------------
  1779. Dave Fleck   email:dfleck@wacom.com      phone:360-750-8882x154
  1780. Wacom Technology Corp.                          sales@wacom.com
  1781. 501 S.E. Columbia Shores Blvd, #300           support@wacom.com
  1782. Vancouver, WA 98661                           WWW/FTP:wacom.com
  1783. - ----------------------------------------------------------------
  1784.  
  1785. +++++++++++++++++++++++++++
  1786.  
  1787. >From tom@jlc.com (Thomas R. Kimpton)
  1788. Date: Wed, 20 Sep 1995 12:10:02 -0600
  1789. Organization: Jostens Learning Corporation
  1790.  
  1791. One technique that I have used in the past where dropping into
  1792. the debugger wasn't an option, and logging wasn't getting flushed
  1793. in time/took too long, was to create a bunch of cursors numbering
  1794. 00 - 99, and made a call to set the cursor and return the number
  1795. of the previous cursor:
  1796.  
  1797. routine1()
  1798. {
  1799. short oldCursor = setDebugCursor(15);
  1800.     ...
  1801.     (void) setDebugCursor(oldCursor);
  1802. }
  1803.  
  1804. This way when the machine froze, the cursor would tell me what
  1805. routine it had frozen in.
  1806.  
  1807. Tom.
  1808.  
  1809. -- 
  1810. Tom Kimpton                 tom@jlc.com
  1811. Jostens Learning Corporation
  1812. (801) 223-3228
  1813.  
  1814. ---------------------------
  1815.  
  1816. >From darick@helix.nih.gov (Darick DeHart)
  1817. Subject: GWorlds = 8k overhead?
  1818. Date: Fri, 15 Sep 1995 19:49:15 GMT
  1819. Organization: ICS/NINDS/NIH
  1820.  
  1821. I've written this program that uses several gworlds.  I noticed that no
  1822. matter what size the actual bit map is, the gworld takes up an additional
  1823. 8k of space.    (For calculating the size of the bitmap I took into
  1824. account the depth - one byte, and the gworld's rowBytes.)  
  1825.  
  1826. It's not really a problem I just want to know whether I'm doing something
  1827. wrong or if there really is that much overhead for gworlds.  If there is
  1828. 8k of overhead then what is taking up all that space?
  1829.  
  1830. Darick
  1831.  
  1832. -- 
  1833. Darick DeHart
  1834. darick@helix.nih.gov
  1835. ICS/NINDS/NIH
  1836.  
  1837. +++++++++++++++++++++++++++
  1838.  
  1839. >From andrewwelc@aol.com (AndrewWelc)
  1840. Date: 15 Sep 1995 21:03:39 -0400
  1841. Organization: America Online, Inc. (1-800-827-6364)
  1842.  
  1843. > It's not really a problem I just want to know whether I'm doing
  1844. something
  1845. > wrong or if there really is that much overhead for gworlds.  If there is
  1846. > 8k of overhead then what is taking up all that space?
  1847.  
  1848. Nope, that's about right.
  1849.  
  1850. Regards,
  1851.  
  1852. Andrew Welch
  1853. Thaumaturgist
  1854. Ambrosia Software, Inc.
  1855.  
  1856. ..........
  1857.  
  1858. For the latest versions of our software, technical support, and Ambrosia
  1859. news, stop by and visit the Ambrosia Software, Inc. support forums:
  1860.  
  1861. America Online ---> Keyword: Ambrosia
  1862.     CompuServe ---> GO word: Ambrosia
  1863.         eWorld --> Shortcut: Ambrosia
  1864.  
  1865. +++++++++++++++++++++++++++
  1866.  
  1867. >From Scott Thompson <sthompson@macromedia.com>
  1868. Date: 16 Sep 1995 14:57:04 GMT
  1869. Organization: Macromedia
  1870.  
  1871. The extra overhead may be accounted for in at least the following:
  1872.  
  1873. The pixel data (duh) :-)
  1874. The associated "device" (if a new one was created)
  1875. The color table
  1876. The device's inverse table
  1877. The CGrafPtr and it's associated stuff 
  1878.      (regions, patterns, "grafVars" etc.)
  1879.  
  1880.  
  1881. Junk like that.  evidently that all adds up to about 8k... but what's 8k 
  1882. among friends.
  1883.  
  1884. Scott
  1885.  
  1886.  
  1887.  
  1888. ---------------------------
  1889.  
  1890. >From Fang-Pin Chang <fpchang@cs.ucsd.edu>
  1891. Subject: How to Find System Folder on Startup Volume
  1892. Date: 21 Sep 1995 21:45:27 GMT
  1893. Organization: The University of California at San Diego
  1894.  
  1895. Hi!  I am new to this newsgroup.  I've been working on a pet project
  1896. at home to learn more about programming for the Mac, and I am at a
  1897. point where I am learning about the File Manager.  I am at a point
  1898. where I can recursively visit all directories and get info on all
  1899. files on all volumes.  However, I have a couple of questions that I
  1900. don't have answers to:
  1901.  
  1902. 1.  How do I determine which is the startup volume?  Is the volume
  1903.     that was mounted first always the startup volume?
  1904.  
  1905. 2.  How do I locate the System Folder on a bootable volume?  I can
  1906.     search for it exhuastively, but that won't account for multiple
  1907.     folders with the same name.
  1908.  
  1909. Any help would be much appreciated.  Thanks!
  1910.  
  1911.  
  1912. +++++++++++++++++++++++++++
  1913.  
  1914. >From jumplong@aol.com (Jump Long)
  1915. Date: 22 Sep 1995 04:53:29 -0400
  1916. Organization: America Online, Inc. (1-800-827-6364)
  1917.  
  1918. Fang-Pin Chang <fpchang@cs.ucsd.edu> wrote:
  1919.  
  1920. >1.  How do I determine which is the startup volume?  Is the
  1921. >volume that was mounted first always the startup volume?
  1922. >
  1923. >2.  How do I locate the System Folder on a bootable volume?  I
  1924. >can search for it exhuastively, but that won't account for
  1925. >multiple folders with the same name.
  1926.  
  1927. Call FindFolder like this:
  1928.  
  1929. result = FindFolder(kOnSystemDisk, kSystemFolderType, kCreateFolder,
  1930.                     &foundVRefNum, &foundDirID);
  1931.  
  1932. If result is noErr after calling FindFolder, then foundVRefNum will
  1933. contain the volume reference number of the boot volume adn foundDirID will
  1934. contain the directory ID number of the current System Folder.
  1935.  
  1936. - Jim Luther
  1937.  
  1938. +++++++++++++++++++++++++++
  1939.  
  1940. >From Binky the Wonderwhorse <binky@mmcorp.com>
  1941. Date: 22 Sep 1995 09:20:43 GMT
  1942. Organization: MultiMedia Corporation
  1943.  
  1944. lo,
  1945.  
  1946. boot volume has volRefNum -1
  1947. find system folder by using volRefNum -1 and use a pathname to the system
  1948. folder.  you shouldn't be able to have multiple system folders with the
  1949. same name.  even still, I guess it is possible so try calling
  1950.  
  1951. OSErr
  1952. FindFolder(short vRefNum, OSType folderType, Boolean createFolder, short
  1953. &foundVRefNum, long &foundDirID);
  1954.  
  1955. using
  1956.  
  1957. short   theVref
  1958. long            theDir
  1959. iErr = FindFolder(-1, 'macs', FALSE, &theVref, &theDir);
  1960.  
  1961. Binky
  1962.  
  1963. ---------------------------
  1964.  
  1965. >From petrich@netcom.com (Loren Petrich)
  1966. Subject: How to convert a raster image into a PICT?
  1967. Date: Fri, 8 Sep 1995 05:45:24 GMT
  1968. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  1969.  
  1970.  
  1971.         I'm trying to write a converter that turns PBMPlus image files 
  1972. into PICT ones. I can read the PBMPlus image OK (a raster image with a 
  1973. simple header), but I have a hard time getting its contents into a PICT 
  1974. file. What I have been doing is something like:
  1975.  
  1976. RGBColor cval;
  1977.  
  1978. OpenCPictureParam picdef;
  1979. [set the image rectangle, etc. from the dimensions in the PBMPlus file's 
  1980. header]
  1981.  
  1982. pic = OpenCPicture(&picdef);
  1983.  
  1984. [Loop over coordinates h and v]
  1985. [set cval to the color value read in from the PBMPlus file]
  1986.  
  1987. SetCPixel(h,v,&cval);
  1988. [End loop]
  1989.  
  1990. ClosePicture();
  1991.  
  1992. [code to copy "pic" to the scrap and write it out...]
  1993.  
  1994. However, it does not seem to produce any picture at all. What's going wrong?
  1995.  
  1996. -- 
  1997. Loren Petrich                           Happiness is a fast Macintosh
  1998. petrich@netcom.com                      And a fast train
  1999. Visit my ftp site; its address is (in WWW syntax):
  2000. ftp://ftp.netcom.com/pub/pe/petrich
  2001.  
  2002. +++++++++++++++++++++++++++
  2003.  
  2004. >From tg3@u.washington.edu (Thurman Gillespy III)
  2005. Date: Fri, 08 Sep 1995 16:49:23 -0800
  2006. Organization: Dept of Radiology, Univ of Washington
  2007.  
  2008. In article <petrichDEKnzo.JLC@netcom.com>, petrich@netcom.com (Loren
  2009. Petrich) wrote:
  2010.  
  2011. >        I'm trying to write a converter that turns PBMPlus image files 
  2012. >into PICT ones. I can read the PBMPlus image OK (a raster image with a 
  2013. >simple header), but I have a hard time getting its contents into a PICT 
  2014. >file. What I have been doing is something like:
  2015. [snip]
  2016.  
  2017. Make a GWorld. Stuff your pixels into the GWorld pixMap. Then make a Picture
  2018. by CopyBiting to/from the same GWorld. Make sure the color table of the
  2019. GWorld is what you want for your PICT. Save the Picture handle as a PICT
  2020. file.
  2021.  
  2022. Holler if you need code.
  2023.  
  2024. -- 
  2025. Thurman Gillespy III             |  tg3@u.washington.edu
  2026. Department of Radiology, SB-05   |  voice (206)543-3320
  2027. University of Washington         |  fax   (206)543-6317
  2028. Seattle, WA 98195                |
  2029.  
  2030. +++++++++++++++++++++++++++
  2031.  
  2032. >From petrich@netcom.com (Loren Petrich)
  2033. Date: Sat, 9 Sep 1995 15:58:19 GMT
  2034. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  2035.  
  2036. In article <tg3-0809951649230001@gillespy.rad.washington.edu>,
  2037. Thurman Gillespy III <tg3@u.washington.edu> wrote:
  2038. >In article <petrichDEKnzo.JLC@netcom.com>, petrich@netcom.com (Loren
  2039. >Petrich) wrote:
  2040. >>        I'm trying to write a converter that turns PBMPlus image files 
  2041. >>into PICT ones. I can read the PBMPlus image OK (a raster image with a 
  2042. >>simple header), but I have a hard time getting its contents into a PICT 
  2043. >>file. What I have been doing is something like:
  2044. >[snip]
  2045.  
  2046. >Make a GWorld. Stuff your pixels into the GWorld pixMap. Then make a Picture
  2047. >by CopyBiting to/from the same GWorld. Make sure the color table of the
  2048. >GWorld is what you want for your PICT. Save the Picture handle as a PICT
  2049. >file.
  2050.  
  2051.         I've created GWorlds for some other stuff, so I'm sure that's no 
  2052. trouble. The problem is with CopyBits -- it will want a destination 
  2053. structure to copy the image to -- and how does one get that from a PicHandle?
  2054.  
  2055.         And I'm sure I'll have to specify the compression to be used in 
  2056. copying to the PicHandle, since I don't think I want to write out an 
  2057. uncompressed image file if I can possibly avoid it.
  2058.  
  2059.         Also, I hope it is not too difficult to specify a palette for a 
  2060. GWorld -- I'd like to do binary and grayscale images that way -- just 
  2061. specify black and white, or 256 grays.
  2062.  
  2063. -- 
  2064. Loren Petrich                           Happiness is a fast Macintosh
  2065. petrich@netcom.com                      And a fast train
  2066. Visit my ftp site; its address is (in WWW syntax):
  2067. ftp://ftp.netcom.com/pub/pe/petrich
  2068.  
  2069. +++++++++++++++++++++++++++
  2070.  
  2071. >From mpeirce@outpost.peircesw.com (Michael Peirce)
  2072. Date: Fri, 15 Sep 95 15:08:37 PT
  2073. Organization: Peirce Software, Inc.
  2074.  
  2075.  
  2076. In article <petrichDEnB17.Hz6@netcom.com> (comp.sys.mac.programmer.help), petrich@netcom.com (Loren Petrich) writes:
  2077. >       I've created GWorlds for some other stuff, so I'm sure that's no 
  2078. > trouble. The problem is with CopyBits -- it will want a destination 
  2079. > structure to copy the image to -- and how does one get that from a PicHandle?
  2080.  
  2081. While you're recording your picture, just CopyBits from the GWorld
  2082. pixmap to *itself*.  Works great.
  2083.  
  2084. >       And I'm sure I'll have to specify the compression to be used in 
  2085. > copying to the PicHandle, since I don't think I want to write out an 
  2086. > uncompressed image file if I can possibly avoid it.
  2087.  
  2088. It should just use the standard QuickDraw RLE encoding.
  2089.  
  2090. >       Also, I hope it is not too difficult to specify a palette for a 
  2091. > GWorld -- I'd like to do binary and grayscale images that way -- just 
  2092. > specify black and white, or 256 grays.
  2093.  
  2094. Simple, when you create your GWorld, pass in a clut.
  2095.  
  2096. --
  2097. Michael Peirce           mpeirce@peircesw.com
  2098. Peirce Software Inc.     719 Hibiscus Place, San Jose California 95117 USA
  2099.                          voice: +1 408 244 6554,      fax: +1 408 244 6882
  2100.  
  2101. Makers of Peirce Print Tools, Smoothie, AppSizer, DeskPicture, & ShareDraw
  2102.  
  2103. <ftp://mirrors.aol.com/pub/info-mac/cfg/app-sizer-22.hqx>
  2104. <ftp://mirrors.aol.com/pub/info-mac/gui/desk-picture-401.hqx>
  2105. <ftp://mirrors.aol.com/pub/info-mac/gst/grf/share-draw-20.hqx>
  2106.  
  2107. +++++++++++++++++++++++++++
  2108.  
  2109. >From petrich@netcom.com (Loren Petrich)
  2110. Date: Wed, 20 Sep 1995 03:46:01 GMT
  2111. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  2112.  
  2113. In article <CNjbKKKX.7uhrkk@outpost.peircesw.com>,
  2114. Michael Peirce <mpeirce@outpost.peircesw.com> wrote:
  2115.  
  2116. >In article <petrichDEnB17.Hz6@netcom.com> (comp.sys.mac.programmer.help), petrich@netcom.com (Loren Petrich) writes:
  2117. >>      I've created GWorlds for some other stuff, so I'm sure that's no 
  2118. >> trouble. The problem is with CopyBits -- it will want a destination 
  2119. >> structure to copy the image to -- and how does one get that from a PicHandle?
  2120.  
  2121. >While you're recording your picture, just CopyBits from the GWorld
  2122. >pixmap to *itself*.  Works great.
  2123.  
  2124.         Thanx. It's curious that I was unable to find this trick in 
  2125. _Inside Macintosh_ and a book that was titled (I think) _Programming with 
  2126. QuickDraw_. So what I'll have to do is:
  2127.  
  2128. Get the image dimensions [I have that]
  2129.  
  2130. Create a GWorld with its dimensions, presumably as a rectangle with bounds
  2131. (0,0) to (horiz-1,vert-1) {or is it (horiz,vert)?}; and also with a clut
  2132. for grayscale or binary (I presume that's easy if one knows the
  2133. appropriate QuickDraw calls -- all my documentation is at work and I'm at
  2134. home as I write this)
  2135.  
  2136. Set every pixel with SetCPixel
  2137.  
  2138. Create a new picture with OpenCPicture
  2139.  
  2140. Perform CopyBits of that GWorld's contents to itself.
  2141.  
  2142. Save that picture.
  2143.  
  2144.  
  2145.         Now that I think about it, I presume it's possible to perform a 
  2146. similar trick for reading in an image.
  2147.  
  2148. Read in the PICT file
  2149.  
  2150. Get its bounding rectangle and work out the dimensions
  2151.  
  2152. Create a GWorld with that bounding rectangle
  2153.  
  2154. Call DrawPicture()
  2155.  
  2156. Read off of that GWorld with GetCPixel
  2157.  
  2158. -- 
  2159. Loren Petrich                           Happiness is a fast Macintosh
  2160. petrich@netcom.com                      And a fast train
  2161. Visit my ftp site; its address is (in WWW syntax):
  2162. ftp://ftp.netcom.com/pub/pe/petrich
  2163.  
  2164. +++++++++++++++++++++++++++
  2165.  
  2166. >From mpeirce@outpost.peircesw.com (Michael Peirce)
  2167. Date: Wed, 20 Sep 95 10:46:39 PT
  2168. Organization: Peirce Software, Inc.
  2169.  
  2170.  
  2171. In article <petrichDF6qGp.7to@netcom.com> (petrich@netcom.com), you write:
  2172. > Set every pixel with SetCPixel
  2173. ...
  2174. > Read off of that GWorld with GetCPixel
  2175.  
  2176. You don't need to use Set/GetCPixel with GWorlds.  It's OK to access
  2177. them directly as memory.  I've done this many times and it works fine.
  2178.  
  2179. No trap overhead as Set/etCPixel does.
  2180.  
  2181. --
  2182. Michael Peirce           mpeirce@peircesw.com
  2183. Peirce Software Inc.     719 Hibiscus Place, San Jose California 95117 USA
  2184.                          voice: +1 408 244 6554,      fax: +1 408 244 6882
  2185.  
  2186. Makers of Peirce Print Tools, Smoothie, AppSizer, DeskPicture, & ShareDraw
  2187.  
  2188. <ftp://mirrors.aol.com/pub/info-mac/cfg/app-sizer-22.hqx>
  2189. <ftp://mirrors.aol.com/pub/info-mac/gui/desk-picture-401.hqx>
  2190. <ftp://mirrors.aol.com/pub/info-mac/gst/grf/share-draw-20.hqx>
  2191.  
  2192. +++++++++++++++++++++++++++
  2193.  
  2194. >From ejensen@server.uwindsor.ca (Erik Jensen)
  2195. Date: Thu, 21 Sep 1995 14:03:54 GMT
  2196. Organization: University of Windsor
  2197.  
  2198. In article <CNjbKKKX.8b8cej@outpost.peircesw.com>,
  2199. mpeirce@outpost.peircesw.com (Michael Peirce) wrote:
  2200.  
  2201. >In article <petrichDF6qGp.7to@netcom.com> (petrich@netcom.com), you write:
  2202. >> 
  2203. >> Set every pixel with SetCPixel
  2204. >> 
  2205. >...
  2206. >> 
  2207. >> Read off of that GWorld with GetCPixel
  2208. >
  2209. >You don't need to use Set/GetCPixel with GWorlds.  It's OK to access
  2210. >them directly as memory.  I've done this many times and it works fine.
  2211. >
  2212. >No trap overhead as Set/etCPixel does.
  2213. >
  2214.  
  2215. Could someone point me to a code fragment that demonstrates this (being an
  2216. extreme newbie I haven't done this before)? Are there Color QD calls that
  2217. access the memory faster or do I read memory directly?
  2218.  
  2219. Thanks,
  2220. Erik.
  2221. __________________________________________________________________________ 
  2222. Erik Jensen                                   ejensen@server.uwindsor.ca
  2223. Department of Physics                         
  2224. University of Windsor                          
  2225. __________________________________________________________________________
  2226.  
  2227. +++++++++++++++++++++++++++
  2228.  
  2229. >From tg3@u.washington.edu (Thurman Gillespy III)
  2230. Date: Thu, 21 Sep 1995 10:29:42 -0800
  2231. Organization: Dept of Radiology, Univ of Washington
  2232.  
  2233. In article <ejensen-2109951003540001@ejensen.esxf.uwindsor.ca>,
  2234. ejensen@server.uwindsor.ca (Erik Jensen) wrote:
  2235.  
  2236. >In article <CNjbKKKX.8b8cej@outpost.peircesw.com>,
  2237. >mpeirce@outpost.peircesw.com (Michael Peirce) wrote:
  2238. >
  2239. >>In article <petrichDF6qGp.7to@netcom.com> (petrich@netcom.com), you write:
  2240. >>> 
  2241. >>> Set every pixel with SetCPixel
  2242. >>> 
  2243. >>...
  2244. >>> 
  2245. >>> Read off of that GWorld with GetCPixel
  2246. >>
  2247. >>You don't need to use Set/GetCPixel with GWorlds.  It's OK to access
  2248. >>them directly as memory.  I've done this many times and it works fine.
  2249. >>
  2250. >>No trap overhead as Set/etCPixel does.
  2251. >>
  2252. >
  2253. >Could someone point me to a code fragment that demonstrates this (being an
  2254. >extreme newbie I haven't done this before)? Are there Color QD calls that
  2255. >access the memory faster or do I read memory directly?
  2256. >
  2257. >Thanks,
  2258. >Erik.
  2259. >__________________________________________________________________________ 
  2260. >Erik Jensen                                   ejensen@server.uwindsor.ca
  2261. >Department of Physics                         
  2262. >University of Windsor                          
  2263. >__________________________________________________________________________
  2264.  
  2265.  
  2266. This works for me. The code fragment assumes you have a valid GWorld and
  2267. the xdim and ydim of the image (which is the same as the portRect of
  2268. the GWorld), and that you have an 8-bit GWorld and 8-bit pixels that
  2269. you are reading/writing to/from the GWorld.
  2270.  
  2271.    // char        *myPixPtr;
  2272.    // long        xdim, ydim;
  2273.    // GWorldPtr   theGWorld;
  2274.  
  2275.    PixMapHandle   pixBaseH  = nil;
  2276.    char           *wp = nil;
  2277.    long           lockPixResult, i, j;
  2278.    Boolean        swapMode;
  2279.    short          rowBytes;
  2280.    SInt8          mmuMode;
  2281.  
  2282.  
  2283.    /* get handle to pixMap of GWorld */
  2284.    pixBaseH = theGWorld->portPixMap;
  2285.    // make sure this isn't nil!
  2286.    lockPixResult = LockPixels(pixBaseH);           // lock it down
  2287.    // make sure lockPixResult == true !
  2288.    
  2289.    // switch to 32-bit addressing mode if 32-bit capable
  2290.    // and started in 24 bit mode
  2291.    // version suggested by Mac Programming FAQ
  2292.    swapMode = PixMap32Bit(pixBaseH);   // need 32bit addressing?
  2293.    if (swapMode) {                  // if so, switch into 32 bit mode
  2294.       mmuMode = true32b;
  2295.       SwapMMUMode(&mmuMode);
  2296.    }
  2297.  
  2298.    // calculate the 'extra' bytes at the end of each row in the GWorld
  2299.    rowBytes = (*pixBaseH)->rowBytes;   // GWorld rowBtyes
  2300.    rowBytes &= ~0x8000;                // mask high bit
  2301.    extraBytes = rowBytes - xdim;       // extra bytes at end of each row
  2302.    
  2303.    // now get a pointer to the GWorld pixels
  2304.    wp = (char *)(GetPixBaseAddr(pixBaseH)); // valid 32-bit pointer
  2305.    // make sure wp != nil !
  2306.    // now read/write to the GWorld pixels, taking care to step over
  2307.    // the 'extra' bytes at the end of each row
  2308.    for (i = 0; i < ydim; i++) {
  2309.       for (j = 0; j < xdim; j++) {
  2310.          // lets assume we are writing to the pixMap
  2311.          *wp++ = *myPixPtr++;
  2312.       }
  2313.       // now step over the extra bytes
  2314.       wp += extraBytes;
  2315.    }
  2316.  
  2317.    if (swapMode)
  2318.       SwapMMUMode(&mmuMode);
  2319.  
  2320.    UnlockPixels(pixBaseH);
  2321.    
  2322. } /* ImagePixelsToGWorld */
  2323.  
  2324. Hope this helps.
  2325.  
  2326. -- 
  2327. Thurman Gillespy III             |  tg3@u.washington.edu
  2328. Department of Radiology, SB-05   |  voice (206)543-3320
  2329. University of Washington         |  fax   (206)543-6317
  2330. Seattle, WA 98195                |
  2331.  
  2332. ---------------------------
  2333.  
  2334. >From hunt@scws4.harvard.edu (Timothy Hunt)
  2335. Subject: How to loop QT movies?
  2336. Date: 21 Sep 1995 13:46:25 GMT
  2337. Organization: Harvard University, Cambridge, Massachusetts
  2338.  
  2339. I would like to know the best way to loop a quicktime movie.  I can not
  2340. seem to find anything in NIM to loop automatically, so maybe my program
  2341. must restart the movie itself from the beginning when it is done?
  2342. There is some references to looping in the TimeBase stuff - Does that
  2343. contain the answer?
  2344.  
  2345. If that is the case, should I set up some kind of call back to notify me
  2346. when my movie has finished?  Can I restart from such a call back which
  2347. would probably occur at interupt time?
  2348.  
  2349. I've also heard that there is some bit that must be set to get smooth
  2350. looping.  Any info here?
  2351.  
  2352. BTW, I'm actually only playing the sound track of a blank movie to use
  2353. Quicktime's music.
  2354.  
  2355. Thanks alot for any help!!
  2356.  
  2357. -Tim
  2358. (hunt@fas.harvard.edu)
  2359.  
  2360.  
  2361. +++++++++++++++++++++++++++
  2362.  
  2363. >From "Andrew C. Plotkin" <erkyrath+@CMU.EDU>
  2364. Date: Thu, 21 Sep 1995 11:27:05 -0400
  2365. Organization: Carnegie Mellon, Pittsburgh, PA
  2366.  
  2367. hunt@scws4.harvard.edu (Timothy Hunt) writes:
  2368. > I would like to know the best way to loop a quicktime movie.  I can not
  2369. > seem to find anything in NIM to loop automatically, so maybe my program
  2370. > must restart the movie itself from the beginning when it is done?
  2371. > There is some references to looping in the TimeBase stuff - Does that
  2372. > contain the answer?
  2373.  
  2374. What I do is:
  2375.  
  2376.         tb = GetMovieTimeBase(mov);
  2377.         SetTimeBaseFlags(tb, loopTimeBase);
  2378.  
  2379. > I've also heard that there is some bit that must be set to get smooth
  2380. > looping.  Any info here?
  2381.  
  2382. There may be a delay unless you load the entire movie into RAM. That's
  2383. the only way I know to deal with it. (If there's another, I'd really
  2384. like to know about it...)
  2385.  
  2386. --Z
  2387.  
  2388. "And Aholibamah bare Jeush, and Jaalam, and Korah: these were the borogoves..."
  2389.  
  2390. +++++++++++++++++++++++++++
  2391.  
  2392. >From tkmower@sdt.com (Terrence Kelly Mower)
  2393. Date: Thu, 21 Sep 1995 13:28:25 -0500
  2394. Organization: SABRE Decision Technologies
  2395.  
  2396. In article <43rqbh$cvs@decaxp.harvard.edu>, hunt@scws4.harvard.edu
  2397. (Timothy Hunt) wrote:
  2398.  
  2399. > I would like to know the best way to loop a quicktime movie.  I can not
  2400. > seem to find anything in NIM to loop automatically, so maybe my program
  2401. > must restart the movie itself from the beginning when it is done?
  2402.  
  2403. Tim,
  2404.  
  2405. Try this:
  2406.  
  2407.    Boolean wantLooping = TRUE;
  2408.    MCDoAction(theController, mcActionActivate, NULL);
  2409.    MCDoAction(theController, mcActionSetLooping, &wantLooping);
  2410.  
  2411.    StartMovie(theMovie);
  2412.  
  2413. This will work, but I'me having a problem with the play button on the
  2414. controller. I have to click it twice to get the movie to stop playing. If
  2415. I click on the movie itself, it stops playing immediately. Maybe someone
  2416. knows why?
  2417.  
  2418. Hope this helps,
  2419.  
  2420. Kelly
  2421.  
  2422. tkmower@sdt.com
  2423.  
  2424. -- 
  2425. T. Kelly Mower
  2426. SABRE Decision Technologies
  2427. tkmower@sdt.com
  2428.  
  2429. +++++++++++++++++++++++++++
  2430.  
  2431. >From hunt@scws4.harvard.edu (Timothy Hunt)
  2432. Date: 21 Sep 1995 18:28:00 GMT
  2433. Organization: Harvard University, Cambridge, Massachusetts
  2434.  
  2435. Andrew C. Plotkin (erkyrath+@CMU.EDU) wrote:
  2436. : hunt@scws4.harvard.edu (Timothy Hunt) writes:
  2437. : > I would like to know the best way to loop a quicktime movie.  I can not
  2438. : > seem to find anything in NIM to loop automatically, so maybe my program
  2439. : > must restart the movie itself from the beginning when it is done?
  2440. : > There is some references to looping in the TimeBase stuff - Does that
  2441. : > contain the answer?
  2442.  
  2443. : What I do is:
  2444.  
  2445. :       tb = GetMovieTimeBase(mov);
  2446. :       SetTimeBaseFlags(tb, loopTimeBase);
  2447. So is the above all you need to do to get looping (ignoring smoothness)?
  2448.  
  2449. Thanks again
  2450. -Tim
  2451. (hunt@fas.harvard.edu)
  2452.  
  2453.  
  2454. +++++++++++++++++++++++++++
  2455.  
  2456. >From ldo@waikato.ac.nz (Lawrence D'Oliveiro)
  2457. Date: Fri, 22 Sep 1995 18:20:48 +1200
  2458. Organization: University of Waikato
  2459.  
  2460. In article <43rqbh$cvs@decaxp.harvard.edu>, hunt@scws4.harvard.edu
  2461. (Timothy Hunt) wrote:
  2462.  
  2463. >I would like to know the best way to loop a quicktime movie.  I can not
  2464. >seem to find anything in NIM to loop automatically, so maybe my program
  2465. >must restart the movie itself from the beginning when it is done?
  2466. >There is some references to looping in the TimeBase stuff - Does that
  2467. >contain the answer?
  2468.  
  2469. That is one answer. If your movie has a controller, then the controller is
  2470. also able to provide another.
  2471.  
  2472. >If that is the case, should I set up some kind of call back to notify me
  2473. >when my movie has finished?
  2474.  
  2475. Yes, this would be an answer as well.
  2476.  
  2477. >  Can I restart from such a call back which
  2478. >would probably occur at interupt time?
  2479.  
  2480. I believe you can choose whether your callback is triggered at interrupt
  2481. or non-interrupt time. You certainly couldn't make most Movie Toolbox
  2482. calls at interrupt time.
  2483.  
  2484. >I've also heard that there is some bit that must be set to get smooth
  2485. >looping.  Any info here?
  2486.  
  2487. I guess this must be the new hintsLoop bit added to the PlayHints in
  2488. QuickTime 2.0. Odd--it's in my interface file, but I can't see it
  2489. mentioned anywhere in this "QuickTime 2.0 Developer Guide for Macintosh" I
  2490. have in front of me.
  2491.  
  2492. ---------------------------
  2493.  
  2494. >From kenlong@netcom.com (Ken Long)
  2495. Subject: Novice Tech Tip #1 - SetRect.
  2496. Date: Mon, 18 Sep 1995 15:24:26 GMT
  2497. Organization: NETCOM On-line Communication Services (408 261-4700 guest)
  2498.  
  2499.  
  2500. While under development, you can save yourself a lot of aggravation, if 
  2501. you are setting many rectangles, by following a couple easy methods and 
  2502. using a couple indispensible utility.
  2503.  
  2504. One utility is "MouseLoc F-Key" it's as "handy as a pocket on a shirt"(tm).
  2505. It gives local and global mouse coodrdinates, as well as click one and 
  2506. click two coordinates.  Of ALL the mouse location utilities, MouseLoc is 
  2507. the best one.  (The other utility is CMaster.)
  2508.  
  2509. MouseLoc F-Keys useful for determining where the coordinates are (or
  2510. should be) for rectangles within your program windows.  It's also great
  2511. for determining MoveTo and LineTo coords.  No need to fire up an 
  2512. additional program, or bring one to front to block your view.
  2513.  
  2514. The tip I wanted to mention is that if you have several rectangles that 
  2515. have somthing to do with each other, are in the same area of your window, 
  2516. and possibly have one edge in alignment, it's easier, while under 
  2517. development, to base subsequent rectangles off a base of some sort, and 
  2518. then just use the original coords and add offset additions, rather than 
  2519. trying to dial in the exact coords.  Then later, once the position is 
  2520. finalized, go back, with a calculator, and determine the exact coords and 
  2521. change them.
  2522.  
  2523. For example, say you want 3 rects lined up horizontally, all the same size.
  2524.  
  2525. SetRect (&rectOne, 20, 50, 75, 75);
  2526.  
  2527. That's the first rect.  What I do is tripple click to sellct the whole 
  2528. line, type Command C, and Command V *3 times*.  Now I have:
  2529.  
  2530. SetRect (&rectOne, 20, 50, 75, 75);
  2531. SetRect (&rectOne, 20, 50, 75, 75);
  2532. SetRect (&rectOne, 20, 50, 75, 75);
  2533.  
  2534. Now I didn't have to retype for the other two rects.  So I change the 
  2535. names next:
  2536.  
  2537. SetRect (&rectOne, 20, 50, 75, 75);
  2538. SetRect (&rectTwo, 20, 50, 75, 75);
  2539. SetRect (&rectTri, 20, 50, 75, 75);
  2540.  
  2541. Now, just add offsets on the horizontal and see how they look:
  2542.  
  2543. SetRect (&rectOne, 20,  50,  75, 75);
  2544. SetRect (&rectTwo, 20 + 60,  50, 75 + 60, 75);
  2545. SetRect (&rectTri, 20 + 60 + 60, 50, 75 + 60 + 60, 75);
  2546.  
  2547. After the first "+ 60+ of course I copied that and merely pasted it onto 
  2548. the other coodrds.  Reduce typing at every opportunity.
  2549.  
  2550. Can't see how they look?  Either frame them temporarily, or "wash" them 
  2551. over a "dirty" background.  Framing is the easiest.  Copy all three lines 
  2552. (to save typing), and paste them in below the SetRect calls and delete 
  2553. the coords:
  2554.  
  2555. SetRect (&rectOne);
  2556. SetRect (&rectTwo);
  2557. SetRect (&rectTri);
  2558.  
  2559. Then change SetRect to FrameRect.  Using CMaster, all you have to do is 
  2560. double-click the first "SetRect" and hit the down or up search icon (to 
  2561. get "SetRect" in the queue as the search string), type "FrameRect", 
  2562. double-click that, copy and deselect.  Now click the down search icon and 
  2563. paste, click, paste, click paste - for as many SetRect calls you have to 
  2564. change.  It's a snap!
  2565.  
  2566. Once you get all your rectangles finalized for position, delete all the 
  2567. FrameRect calls and you're rolling.  You can also go back ad add up the 
  2568. coords/offsets and type in the real value (I could have said "true value" 
  2569. but those are hardware items).
  2570.  
  2571. MouseLoc F-Key, CMaster and QuicKeys are essential Think C programming 
  2572. tools - the last two for all around coding and the first one for graphics.
  2573.  
  2574. The "wipe" over a "dirty" background refers to erasing the window (or 
  2575. painting it) with the lightest gray RGB, then erasing your rectangles 
  2576. after you set them, to see where they are.
  2577.  
  2578. -Ken-
  2579.  
  2580. +++++++++++++++++++++++++++
  2581.  
  2582. >From pottier@galion.ens.fr (Francois Pottier)
  2583. Date: 19 Sep 1995 12:52:30 GMT
  2584. Organization: Ecole Normale Superieure, Paris
  2585.  
  2586. In article <kenlongDF3xGq.34M@netcom.com>, Ken Long <kenlong@netcom.com> wrote:
  2587.  
  2588. > You can also go back ad add up the coords/offsets and type in the
  2589. > real value
  2590.  
  2591. You don't have to do that. The compiler should be smart enough to compute
  2592. the expression for you at compile-time. This way, you can keep your code
  2593. more readable and easier to change.
  2594.  
  2595. -- 
  2596. Francois Pottier                                            pottier@dmi.ens.fr
  2597. - ----------------------------------------------------------------------------
  2598. Check my WWW page at http://acacia.ens.fr:8080/home/pottier/ ...
  2599.  
  2600. +++++++++++++++++++++++++++
  2601.  
  2602. >From Scott Thompson <sthompson@macromedia.com>
  2603. Date: 19 Sep 1995 14:16:06 GMT
  2604. Organization: Macromedia
  2605.  
  2606. As a side note, if you're calling SetRect many many times in a tight 
  2607. loop, you might also consider simply assigning each coordinate of the 
  2608. rect rather than calling SetRect (i.e.  myRect.top = 12; myRect.left = 
  2609. 5+37, etc.)
  2610.  
  2611. That way you avoid the overhead of the trap dispatcher.
  2612.  
  2613. Scott Thompson 
  2614.  
  2615.  
  2616.  
  2617. +++++++++++++++++++++++++++
  2618.  
  2619. >From Carl R. Osterwald <carl_osterwald@nrel.gov>
  2620. Date: 19 Sep 1995 15:32:05 GMT
  2621. Organization: National Renewable Energy Laboratory
  2622.  
  2623. In article <kenlongDF3xGq.34M@netcom.com> Ken Long, kenlong@netcom.com
  2624. writes:
  2625.  
  2626. >SetRect (&rectOne, 20, 50, 75, 75);
  2627. >SetRect (&rectOne, 20, 50, 75, 75);
  2628. >SetRect (&rectOne, 20, 50, 75, 75);
  2629.  
  2630. When you have lots of Rects to deal with, another way to create them is
  2631. it steal the 'nrct' resource that was originally created for control
  2632. panels.  It saves you from having to code each one, and the built-in
  2633. TMPL allows editing outside of the source.  The resource gives you an
  2634. array for easy indexing:
  2635.  
  2636. typedef struct
  2637.   {
  2638.     short  no_of_rects;
  2639.     Rect   nrcts[1];
  2640.   } nrct;
  2641. typedef nrct *nrctPtr, *nrctHandle;
  2642.  
  2643. This is great way to handle baloon help manually.
  2644.  
  2645. +++++++++++++++++++++++++++
  2646.  
  2647. >From A_student@postoffice.utas.edu.au (A Student)
  2648. Date: Wed, 20 Sep 1995 13:30:11 +1100
  2649. Organization: University of Tasmania
  2650.  
  2651.  
  2652. > One utility is "MouseLoc F-Key" it's as "handy as a pocket on a shirt"(tm).
  2653. > It gives local and global mouse coodrdinates, as well as click one and 
  2654. > click two coordinates.  Of ALL the mouse location utilities, MouseLoc is 
  2655. > the best one.  (The other utility is CMaster.)
  2656.  
  2657. Great Novice Tech Tip #1 Ken but where can I get MouseLoc F-Key?  I have
  2658. looked through Info-Mac but cannot find it, I am assumming that it's a
  2659. demo or shareware.  So if you could pass on a ftp site or even post it in
  2660. alt.source.mac it would be a great help.
  2661. Keep up the good work, you are a great help to novices!
  2662.  
  2663. JT :)
  2664.  
  2665. ---------------------------
  2666.  
  2667. >From tkkuyken@powergrid.electriciti.com (Tod K Kuykendall)
  2668. Subject: Obscure FILEID question
  2669. Date: 19 Sep 1995 23:57:48 GMT
  2670. Organization: Stark Visual Images
  2671.  
  2672.  
  2673.  
  2674. Howdy!
  2675.  
  2676.   I've torn apart IM:Files but I have a couple more questions about the
  2677. FILE ID. 
  2678.   I know it states that once a FILE ID is used it is never reassigned
  2679. to another file - but is it possible to force write a file into a
  2680. different ID? It is part of catalog node (I think) so you'd probably
  2681. mung something if you tried to do this but does anyone know for sure.
  2682. What if a file is deleted but you back it up off another media - the
  2683. FILE ID gets reassigned - but could you force back into it's original
  2684. ID or not?
  2685.    Is there another way to force (or influence the creation of a FILE
  2686. ID number) to cause a file to reuse an ID? What if you brute force copy
  2687. the sector off onto something else, delete the original and the write
  2688. it back. What else would you have to notify/update to get the file
  2689. noticed again?
  2690.  
  2691. Any and all thoughts/theories/suggestions welcomed....
  2692.  
  2693. =tkk
  2694.  
  2695.  
  2696.  
  2697. "I just want to say the sooner we get that filthy Rosanne off the air
  2698. American TV will be better for it. PS I love Hard Copy."
  2699.   -viewer reaction on Hard Copy's 1-900 number response line
  2700.  
  2701. +++++++++++++++++++++++++++
  2702.  
  2703. >From becker@Xenon.Stanford.EDU (Denizen of the Deep)
  2704. Date: 20 Sep 1995 01:22:57 GMT
  2705. Organization: Computer Science Department, Stanford University.
  2706.  
  2707. In article <43nlds$qsi@watt.electriciti.com>,
  2708. Tod K Kuykendall <tkkuyken@powergrid.electriciti.com> wrote:
  2709. >
  2710. >
  2711. >Howdy!
  2712. >
  2713. >  I've torn apart IM:Files but I have a couple more questions about the
  2714. >FILE ID. 
  2715. >  I know it states that once a FILE ID is used it is never reassigned
  2716. >to another file - but is it possible to force write a file into a
  2717. >different ID? It is part of catalog node (I think) so you'd probably
  2718. >mung something if you tried to do this but does anyone know for sure.
  2719. >What if a file is deleted but you back it up off another media - the
  2720. >FILE ID gets reassigned - but could you force back into it's original
  2721. >ID or not?
  2722.  
  2723. What I'm about to say is NOT RECOMMENDED, but since you asked I'll
  2724. give you the story.  It is possible to force a newly created file
  2725. or directory to have some arbitrary file ID (as long as it's not one
  2726. of the reserved IDs mentioned in IM:Files).
  2727.  
  2728. The way the File Manager tries to ensure the uniqueness of IDs on
  2729. a particular volume is by keeping a number around which represents
  2730. the ID for the next created file/folder.  It simply increments
  2731. with every file or folder creation.  The number is a 32-bit value,
  2732. so if you ever created more than about 4 billion files/folders over
  2733. the course of a volume's life, there could be problems (regardless
  2734. of whether or not you throw some of those files away).
  2735.  
  2736. This value is stored in the MDB on disk and in the VCB in memory
  2737. (it's called vcbNxtCNID).  You can retrieve it with a call to
  2738. PBHGetVInfo.  Its value is ignored in a call to PBHSetVInfo,
  2739. so you can't set it that way.
  2740.  
  2741. You can, however, walk the VCB queue in memory and manually set
  2742. the value of this number in the desired volume's VCB to some
  2743. arbitrary value.  The next file or folder you create will then be
  2744. given an ID equal to the value you chose.  If another file or
  2745. folder on the volume already has this value, then probably some
  2746. Bad Things (tm) would occur.
  2747.  
  2748. Well, now that you know how it's done, don't do it!  :-)
  2749.  
  2750. -Jon
  2751.  
  2752. ---------------------------
  2753.  
  2754. >From drysdall@waikato.ac.nz (Richard Drysdall)
  2755. Subject: Q: FindFolder won't link
  2756. Date: Wed, 13 Sep 1995 10:42:11 +1200
  2757. Organization: University of Waikato
  2758.  
  2759. I'm trying to use FindFolder in my Mac application (compiled with Think C
  2760. 7.0.4). The compiler always complains that link failed: undefined
  2761. "FindFolder", even though I've included <Folders.h>. Any suggestions?
  2762. Thanks
  2763. (sorry this is so short - OT problems!).
  2764. -- 
  2765. Richard Drysdall
  2766. University of Waikato
  2767. New Zealand
  2768. "I'm called a theoretical physicist because in practice I'm not."
  2769.  
  2770. +++++++++++++++++++++++++++
  2771.  
  2772. >From tim@dierks.org (Tim Dierks)
  2773. Date: Tue, 12 Sep 1995 23:37:46 +0100
  2774. Organization: Best Internet Communications
  2775.  
  2776. In article <drysdall-1309951042110001@plasma4.phys.waikato.ac.nz>,
  2777. drysdall@waikato.ac.nz wrote:
  2778.  
  2779. >I'm trying to use FindFolder in my Mac application (compiled with Think C
  2780. >7.0.4). The compiler always complains that link failed: undefined
  2781. >"FindFolder", even though I've included <Folders.h>. Any suggestions?
  2782.  
  2783. Either:
  2784.  - Add the library "MacTraps2" to add the FindFolder glue
  2785.      or 
  2786.  - #define SystemSevenOrLater to 1 before including <Folders.h>
  2787.    (assuming that you can in fact assume you're running under System 7).
  2788.  
  2789. Enjoy,
  2790.  - Tim
  2791.  
  2792. -- 
  2793. Tim Dierks
  2794. tim@dierks.org
  2795.  
  2796. +++++++++++++++++++++++++++
  2797.  
  2798. >From axlrosen@tiac.net (Alex Rosen)
  2799. Date: Sat, 16 Sep 1995 14:43:58 -0500
  2800. Organization: The Internet Access Company
  2801.  
  2802. In article <tim-1209952337460001@tdierks.vip.best.com>, tim@dierks.org
  2803. (Tim Dierks) wrote:
  2804.  
  2805. >In article <drysdall-1309951042110001@plasma4.phys.waikato.ac.nz>,
  2806. >drysdall@waikato.ac.nz wrote:
  2807. >
  2808. >>I'm trying to use FindFolder in my Mac application (compiled with Think C
  2809. >>7.0.4). The compiler always complains that link failed: undefined
  2810. >>"FindFolder", even though I've included <Folders.h>. Any suggestions?
  2811. >
  2812. >Either:
  2813. > - Add the library "MacTraps2" to add the FindFolder glue
  2814. >     or 
  2815. > - #define SystemSevenOrLater to 1 before including <Folders.h>
  2816. >   (assuming that you can in fact assume you're running under System 7).
  2817.  
  2818. To be a little more specific:
  2819.  
  2820. In Think C (and I think in all dev environments), FindFolder is
  2821. implemented in glue that allows it to work with System 6, even though the
  2822. trap only exists in System 7. This glue is in MacTraps2 in Think C. If the
  2823. user is running System 6, it uses other system calls to point you to the
  2824. System folder for all requests (since the Extensions, Preferences, etc
  2825. folders don't exist before System 7). If the user is running under System
  2826. 7 or later, it simply calls through to the real FindFolder.
  2827.  
  2828. If you #define SystemSevenOrLater, you're telling Folders.h that you don't
  2829. need the glue since you won't be running under systems earlier than 7. (Or
  2830. you'll check the system version yourself and do the right thing, rather
  2831. than using the glue.)
  2832.  
  2833. --Alex
  2834.  
  2835. ---------------------------
  2836.  
  2837. >From becker@Xenon.Stanford.EDU (Denizen of the Deep)
  2838. Subject: Resource size limits?
  2839. Date: 14 Sep 1995 18:45:50 GMT
  2840. Organization: Computer Science Department, Stanford University.
  2841.  
  2842.  
  2843. I seem to recall that there are some built-in limits on the sizes
  2844. of resources (number of bits in offset field, that sort of thing).
  2845. I think that there is a limit on the size of an individual resource,
  2846. as well as on the total size of all resources in a file.
  2847.  
  2848. Can anybody point me to some documentation on this?  I couldn't
  2849. find anything about it in the Resources chapter of IM: More Mac
  2850. Toolbox. :-(
  2851.  
  2852. -Jon
  2853.  
  2854. +++++++++++++++++++++++++++
  2855.  
  2856. >From jjohnson@crl.com (Jeffrey Johnson)
  2857. Date: 14 Sep 1995 22:35:30 GMT
  2858. Organization: CRL Dialup Internet Access        (415) 705-6060  [Login: guest]
  2859.  
  2860. Denizen of the Deep (becker@Xenon.Stanford.EDU) wrote:
  2861. : I seem to recall that there are some built-in limits on the sizes
  2862. : of resources (number of bits in offset field, that sort of thing).
  2863. : I think that there is a limit on the size of an individual resource,
  2864. : as well as on the total size of all resources in a file.
  2865. : Can anybody point me to some documentation on this?  I couldn't
  2866. : find anything about it in the Resources chapter of IM: More Mac
  2867. : Toolbox. :-(
  2868.  
  2869. TB555 tech note says there is a limit of 2727 resources in a file and 
  2870. that a resource may be up to MAXLONGINT bytes- but from painful 
  2871. experience and from a previous plea for info, it looks like you can only 
  2872. have a resource fork < 16MB. Sigh...
  2873.  
  2874. Thanks
  2875. Jeff
  2876.  
  2877. -- 
  2878. Jeffrey Johnson                                               jjohnson@crl.com
  2879. If you believe what you read, the sky is thick with aliens who are designing
  2880. pyramids, disemboweling livestock, impregnating rural people and generally
  2881. having a good time at our expense.  -Scott Adams
  2882.  
  2883. +++++++++++++++++++++++++++
  2884.  
  2885. >From resorcerer@aol.com (Resorcerer)
  2886. Date: 15 Sep 1995 04:27:47 -0400
  2887. Organization: America Online, Inc. (1-800-827-6364)
  2888.  
  2889. Jon -
  2890.  
  2891. There is a limit of 2727 resources total in a resource file, due to a
  2892. crazy calculation involving 16-bit offsets, blah, blah.  In addition, the
  2893. total size of the file is limited to 16MB, due to computations only being
  2894. done in 24-bit offsets (or some such thing).  Also, you generally don't
  2895. want more than, say, 500 resources (Your Mileage May Vary) of any one
  2896. type, because the resource manager has to traverse the entire list to get
  2897. to the end.
  2898.  
  2899. The only other thing that comes to mind is the fact that Rez computes all
  2900. offsets in bits, not bytes, so if it's keeping all its numbers in longs,
  2901. then 16MB is the largest size (in bytes) in can handle.  I don't know if
  2902. this is the case (not being a Rez user), but it's a thought.
  2903.  
  2904. Doug McKenna
  2905. Mathemaesthetics, Inc.
  2906. Developers of Resorcerer
  2907.  
  2908.  
  2909. +++++++++++++++++++++++++++
  2910.  
  2911. >From becker@Xenon.Stanford.EDU (Denizen of the Deep)
  2912. Date: 15 Sep 1995 15:48:49 GMT
  2913. Organization: Computer Science Department, Stanford University.
  2914.  
  2915. In article <43bde3$8h2@newsbf02.news.aol.com>,
  2916. Resorcerer <resorcerer@aol.com> wrote:
  2917. >Jon -
  2918. >
  2919. >There is a limit of 2727 resources total in a resource file, due to a
  2920. >crazy calculation involving 16-bit offsets, blah, blah.  In addition, the
  2921. >total size of the file is limited to 16MB, due to computations only being
  2922. >done in 24-bit offsets (or some such thing).  Also, you generally don't
  2923. >want more than, say, 500 resources (Your Mileage May Vary) of any one
  2924. >type, because the resource manager has to traverse the entire list to get
  2925. >to the end.
  2926.  
  2927. Yeah, the 16MB limit jibes well with the fact that there are 3 bytes
  2928. in the resource map for a resource's offset from the beginning of the
  2929. data (this suggests to me that the cumulative resource data can't
  2930. be more than 16MB, not that the whole file can't be).  I don't quite
  2931. see where the 2727 comes from.
  2932.  
  2933. But regardless, what I was really looking for was some official
  2934. documentation on this stuff.  Is there any?
  2935.  
  2936. >
  2937. >The only other thing that comes to mind is the fact that Rez computes all
  2938. >offsets in bits, not bytes, so if it's keeping all its numbers in longs,
  2939. >then 16MB is the largest size (in bytes) in can handle.  I don't know if
  2940. >this is the case (not being a Rez user), but it's a thought.
  2941.  
  2942. Hmm, 2^32 bits would be 512 MB as far as I can tell... :-)
  2943.  
  2944. >
  2945. >Doug McKenna
  2946.  
  2947. Thanks for your help, Doug.
  2948.  
  2949. -Jon
  2950.  
  2951. +++++++++++++++++++++++++++
  2952.  
  2953. >From andrewwelc@aol.com (AndrewWelc)
  2954. Date: 15 Sep 1995 21:03:40 -0400
  2955. Organization: America Online, Inc. (1-800-827-6364)
  2956.  
  2957. > But regardless, what I was really looking for was some official
  2958. > documentation on this stuff.  Is there any?
  2959.  
  2960. Yes -- there was a tech note years ago called "Don't abuse the managers". 
  2961. Check Apple's ftp or web site.
  2962.  
  2963. Regards,
  2964.  
  2965. Andrew Welch
  2966. Thaumaturgist
  2967. Ambrosia Software, Inc.
  2968.  
  2969. ..........
  2970.  
  2971. For the latest versions of our software, technical support, and Ambrosia
  2972. news, stop by and visit the Ambrosia Software, Inc. support forums:
  2973.  
  2974. America Online ---> Keyword: Ambrosia
  2975.     CompuServe ---> GO word: Ambrosia
  2976.         eWorld --> Shortcut: Ambrosia
  2977.  
  2978. +++++++++++++++++++++++++++
  2979.  
  2980. >From ckt@best.com (Chris Thomas)
  2981. Date: Sat, 16 Sep 1995 04:34:16 -0800
  2982. Organization: Echo Software
  2983.  
  2984. In article <43bde3$8h2@newsbf02.news.aol.com>, resorcerer@aol.com
  2985. (Resorcerer) wrote:
  2986.  
  2987. > Jon -
  2988. > There is a limit of 2727 resources total in a resource file, due to a
  2989. > crazy calculation involving 16-bit offsets, blah, blah.  In addition, the
  2990. > total size of the file is limited to 16MB, due to computations only being
  2991. > done in 24-bit offsets (or some such thing).  Also, you generally don't
  2992. > want more than, say, 500 resources (Your Mileage May Vary) of any one
  2993. > type, because the resource manager has to traverse the entire list to get
  2994. > to the end.
  2995.  
  2996. $64.00 Q:  What, if any, of this changed with the new Native Resource
  2997. Manager?
  2998.  
  2999. -- 
  3000. Chris Thomas, ckt@best.com
  3001.  
  3002. +++++++++++++++++++++++++++
  3003.  
  3004. >From tim@dierks.org (Tim Dierks)
  3005. Date: Sat, 16 Sep 1995 13:21:46 +0100
  3006. Organization: Best Internet Communications
  3007.  
  3008. In article <ckt-1609950434160001@ckt.vip.best.com>, ckt@best.com (Chris
  3009. Thomas) wrote:
  3010. >In article <43bde3$8h2@newsbf02.news.aol.com>, resorcerer@aol.com
  3011. >(Resorcerer) wrote:
  3012. >> [ Various resource manager limitiations ]
  3013. >$64.00 Q:  What, if any, of this changed with the new Native Resource
  3014. >Manager?
  3015.  
  3016. Probably none of it, since these are all map-format limitations, and the
  3017. map didn't change in the port to native.
  3018.  
  3019.  - Tim
  3020.  
  3021. -- 
  3022. Tim Dierks
  3023. tim@dierks.org
  3024.  
  3025. ---------------------------
  3026.  
  3027. >From Bill Rose
  3028. Subject: [Q] MPW and printf()...Again
  3029. Date: 22 Sep 1995 14:47:19 GMT
  3030. Organization: NIST/ASD/SNLP
  3031.  
  3032. In article <43s0a3$oul@seaman.cc.purdue.edu>, ags@seaman.cc.purdue.edu (Dave Seaman) writes:
  3033. > It's because of the way MPW does input.  Your code will work if you add
  3034. > a newline at the end of your prompt:
  3035. >       printf("Please enter the name of the file to convert>\n");
  3036. >       scanf("%s", &in_name);
  3037. >       inp = fopen(in_name, "r");
  3038. > The reason is that when you press <enter> to send a line of text in
  3039. > MPW, your program sees the entire line (including the "Please ..."
  3040. > prompt).  Putting your response on a spearate line is the easy way to
  3041. > solve the problem.  Otherwise, you would need to have your program
  3042. > recognize and skip over the prompt.
  3043. > Dave Seaman
  3044.  
  3045. To all who answered this:
  3046.  
  3047. First thanks a lot for the input.  I should have mentioned this before, but I had tried the \n and it still didn't work right.  However, the code without the 
  3048. \r was compiled to a SIOW and it did work.  I guess that I'll have to fool with it more to see if I'm messing up somewhere else and try to get it to work on the command line, but I don't think MPW is necessarily friendly with the command line programming or else I simply have to get used to doing things with the new line command in my printf() statements from now on.
  3049.  
  3050. Again, thanks for your help.
  3051.  
  3052. Bill Rose
  3053. wrose@nist.gov
  3054.  
  3055.  
  3056.  
  3057. +++++++++++++++++++++++++++
  3058.  
  3059. >From gregb@genmagic.com (Greg Branche)
  3060. Date: Fri, 22 Sep 1995 21:19:55 -0700
  3061. Organization: General Magic
  3062.  
  3063. In article <43ui9n$qm0@dove.nist.gov>, billr@jaguar.ncsl.nist.gov wrote:
  3064.  
  3065. >First thanks a lot for the input.  I should have mentioned this before, but I 
  3066. >had tried the \n and it still didn't work right.  However, the code
  3067. without the 
  3068. >\r was compiled to a SIOW and it did work.  
  3069.  
  3070. I just thought of another factor in this problem.
  3071.  
  3072. When entering the text in response to the prompt, did you press the
  3073. <Return> key to terminate the input, or did you press the <Enter> key? 
  3074. MPW maintains a distinction between the two, since the "command line" in
  3075. the worksheet can be viewed as just another line in the document that is
  3076. being edited.  (After all, MPW is just a text editor with a few minor
  3077. additions. :-)
  3078.  
  3079. The proper method is to use the <Enter> key to terminate the response. 
  3080. This is a signal to the shell that the line containing the cursor is to be
  3081. processed as stdin.
  3082.  
  3083. Greg Branche
  3084. Magic Cap Entomologist
  3085. General Magic, Inc.
  3086.  
  3087. ---------------------------
  3088.  
  3089. >From reed@medicine.wustl.edu (Thomas Reed)
  3090. Subject: how do I get char minus any modifier key alterations?
  3091. Date: Mon, 18 Sep 1995 16:39:53 -0500
  3092. Organization: Washington University
  3093.  
  3094. I need to capture and display a user's keypress.  For instance, if the
  3095. user presses cmd-opt-p, I want to display "Command + Option + p". 
  3096. Unfortunately, when I get the key pressed from the EventRecord, it is the
  3097. MODIFIED key -- for instance, the character from the above keypress would
  3098. be pi.  This is obviously not what I want -- I don't want to display
  3099. "Command + Option + pi"!
  3100.  
  3101. So...  is there any way that I can modify this character to get the raw
  3102. character rather than the modified character?
  3103.  
  3104. Thanks in advance!
  3105.  
  3106. -Thomas
  3107.  
  3108. =====================================================
  3109. Thomas Reed                     Washington University
  3110. reed@visar.wustl.edu               Medical School
  3111. reed@medicine.wustl.edu            Saint Louis, MO
  3112. http://medinfo.wustl.edu/~reed
  3113. - ---------------------------------------------------
  3114. Clothes make the man.  Naked people have little or no
  3115. influence on society.  -- Mark Twain
  3116. =====================================================
  3117.  
  3118. Opinions posted are not the opinions of Wash. U.
  3119.  
  3120. +++++++++++++++++++++++++++
  3121.  
  3122. >From grobbins@znet.com (Grobbins)
  3123. Date: Mon, 18 Sep 1995 18:33:37 -0700
  3124. Organization: Skunkworks
  3125.  
  3126. In article <reed-1809951639530001@thomasmac.wustl.edu>,
  3127. reed@medicine.wustl.edu (Thomas Reed) wrote:
  3128. >So...  is there any way that I can modify this character to get the raw
  3129. >character rather than the modified character?
  3130.  
  3131. Take the virtual keyCode and reprocess it with KeyTrans.  The technique is
  3132. discussed in tech note TE 515 (Keyboard Resource Q&A's); the appropriate
  3133. section of that note is pasted below.  Be aware that the identifier names
  3134. used in the tech note Q&A are archaic; look in the OLDROUTINENAMES section
  3135. of the current headers for the new names.
  3136.  
  3137. Grobbins                               grobbins@znet.com
  3138.  
  3139.     --------------
  3140.  
  3141.  
  3142.  
  3143. Macintosh Option key: Techniques for ignoring
  3144. Date Written:  10/16/91
  3145. Last reviewed:  2/28/92
  3146. I would like to use the Macintosh Option key as the Control key for
  3147. keyboards that lack a Control key, such as for Macintosh Plus keyboards.
  3148. How can I find the ASCII value that would have been returned if the Option
  3149. key weren’t pressed, in a way that would be compatible with other
  3150. keyboards?
  3151. ___
  3152. There are a couple of clean ways to ignore the Option key. One is to
  3153. “reprocess” the keyboard event. The fourth byte of the event message is
  3154. the ASCII code, but the third byte is the virtual key code. The system
  3155. calls the trap KeyTrans to map the virtual key code to ASCII according to
  3156. a 'KCHR' resource. You can do the same, and since the high byte of the
  3157. modifiers are part of the input to KeyTrans, you can strip out the Option
  3158. key, call KeyTrans on the third byte of the event message, and get back
  3159. the “true” ASCII keypress. KeyTrans and 'KCHR' resources are documented in
  3160. Chapter 10 of Inside Macintosh Volume V, Chapter 14 of Inside Macintosh
  3161. Volume VI (pages 14-23 and 14-96), and the Macintosh Technical Note “Key
  3162. Mapping.” In Pascal, these steps would look something like:
  3163.  
  3164.     keycode := BAND(event.message, keyCodeMask); { get virtual code }
  3165.     keycode := BSR(keycode, 8); { move to low byte }
  3166.     { now combine with modifiers }
  3167.     keycode := BOR(keycode, BAND($FF00, event.modifiers)); 
  3168.     keycode := BAND(keycode, $FFFF - optionKey); { strip option }
  3169.     newkey := KeyTrans(KCHRHandle^, keyCode, state);
  3170.  
  3171. The resource ID of the current KCHR is available as
  3172. GetScript(GetEnvirons(smKeyScript), smScriptKeys). Alternatively, a
  3173. pointer to the KCHR data is available under System 7 as
  3174. GetEnvirons(smKCHRCache), as discussed in the Tech Note “International
  3175. Canceling.”
  3176.  
  3177. This method may work for you, but there is a possible problem: dead keys.
  3178. Since dead keys are processed before your application gets the event, your
  3179. application will not see (for example) the first Option-e typed. However,
  3180. the dead keys are specified in the 'KCHR' resource, so you can create a
  3181. KCHR (ResEdit 2.1.1 includes a template) to omit dead keys (and, if you
  3182. choose, option characters) and include it with your application. Call
  3183. SetScript to get the system to use your 'KCHR' (see the Tech Note “Key
  3184. Mapping,” IM V-313, and IM VI 14-40).
  3185.  
  3186.  
  3187. Another problem is that System 7 ignores a 'KCHR' in the application’s
  3188. resources, so an application’s 'KCHR' has to be installed in the system.
  3189. You can install the 'KCHR' with an installer program, or provide a
  3190. keyboard file users can drag to the System file. (To create a keyboard
  3191. file, use ResEdit to put the 'KCHR' in the System file, and then drag it
  3192. out with the System 7 Finder.)
  3193.  
  3194. +++++++++++++++++++++++++++
  3195.  
  3196. >From Richard Kennaway <jrk@sys.uea.ac.uk>
  3197. Date: 19 Sep 1995 11:50:48 GMT
  3198. Organization: SYS, University of East Anglia
  3199.  
  3200. In article <reed-1809951639530001@thomasmac.wustl.edu> Thomas Reed,
  3201. reed@medicine.wustl.edu writes:
  3202. >So...  is there any way that I can modify this character to get the raw
  3203. >character rather than the modified character?
  3204.  
  3205. For the application you describe, what you want is a mapping from the
  3206. keycode to what is actually drawn on the keycap, but I don't know of any
  3207. way of getting that (in a manner that will deal well with e.g. all the
  3208. keys on the extended keyboard).  Is there any sort of keyboard definition
  3209. resource in the System?
  3210.  
  3211. To find the unmodified character code, this is what I did in code written
  3212. a few years ago (using MPW C and System 6).  Maybe there's a simpler way
  3213. now?
  3214.  
  3215. 1. Take the keyCode from the event record.  Set the upper byte (the
  3216. modifiers byte) to 0.
  3217.  
  3218. 2. Get the relevant KCHR resource (see below).
  3219.  
  3220. 3. Pass these to KeyTranslate to find out what the character code would
  3221. have been if no modifier keys had been pressed.
  3222.  
  3223. 4. KeyTranslate returns a 4-byte result, of which the character code
  3224. could be either the least significant or the third-least significant, so
  3225. you get the character code by:
  3226.  
  3227.     charCode = (((result >> 16)==0) ? result : (result >> 16)) & 255;
  3228.  
  3229. It is possible for both of those bytes to be non-zero in some script
  3230. systems, in which a keystroke can generate a pair of characters.
  3231.  
  3232. Remember to lock the resource handle before KeyTranslate and to restore
  3233. its state after, since KeyTranslate takes a pointer to the KCHR data, not
  3234. a handle.
  3235.  
  3236. How do you find the right KCHR resource?  To be compatible with all
  3237. versions of the system software:
  3238.  
  3239. 1. Test if the Script Manager is present.
  3240.  
  3241. 2. If it is, get the KCHR resource like so:
  3242.  
  3243.     sysKCHRId = GetScript( GetEnvirons( smSystemScript ), smScriptKeys );
  3244.     sysKCHRHandle = GetResource( 'KCHR', (int16) sysKCHRId );
  3245.  
  3246. ("int16" = 2-byte integer type.)
  3247.  
  3248. I'm not absolutely sure that smSystemScript would be correct for you.  I
  3249. use this code when processing menu command-keys, so I want to use the
  3250. script id relevant to drawing menus.  For your application, what you want
  3251. is the script most likely to represent what is drawn on the key caps, and
  3252. unless you have a very fancy keyboard, that doesn't change when you
  3253. change scripts.
  3254.  
  3255. 3. If the Script Manager is absent, or if the above code leaves you with
  3256. a nil sysKCHRHandle, try to get the resource id from the "international"
  3257. resource:
  3258.  
  3259.     if ((itl0 = (Intl0Hndl) IUGetIntl( 0 )) != nil) {
  3260.         sysKCHRId = (((**itl0).intl0Vers) >> 8) & 255;
  3261.         sysKCHRHandle = GetResource( 'KCHR', (int16) sysKCHRId );
  3262.     }
  3263.  
  3264. 4. If that doesn't work, then as a last resort, try:
  3265.  
  3266.     sysKCHRId = 0;
  3267.     sysKCHRHandle = GetResource( 'KCHR', (int16) sysKCHRId );
  3268.  
  3269. It still works for me, but I don't know which branches of the
  3270. KCHR-finding code have ever been executed.  I've also never run it on any
  3271. machine having exotic script systems.
  3272.  
  3273. I can email the relevant code in its working form if anyone wants it.
  3274.  
  3275. ___
  3276. \X/ Richard Kennaway, jrk@sys.uea.ac.uk, http://www.sys.uea.ac.uk/~jrk/
  3277.     School of Information Systems, Univ. of East Anglia, Norwich
  3278.  
  3279. +++++++++++++++++++++++++++
  3280.  
  3281. >From PaulS101@mailbox.ioa.com (Paul Sexton)
  3282. Date: 20 Sep 1995 16:40:32 GMT
  3283. Organization: Vnet Internet Access, Charlotte, NC - info@char.vnet.net
  3284.  
  3285. In article <reed-1809951639530001@thomasmac.wustl.edu>,
  3286. reed@medicine.wustl.edu (Thomas Reed) wrote:
  3287.  
  3288. > I need to capture and display a user's keypress.  For instance, if the
  3289. > So...  is there any way that I can modify this character to get the raw
  3290. > character rather than the modified character?
  3291.  
  3292. /*
  3293. Written in CW6 c++, modified slightly.
  3294. Based on code by: grobbins@zNET.com (Grobbins)
  3295.  
  3296. Function converts inMacEvent.message (the key) as though NO modifiers
  3297. were down, leaves inMacEvent.modifiers alone so you can get at it.
  3298. NO allowance for multi-key characters (option sequences):  you're
  3299. on your own there.  I use this to implement keyboard equivalents
  3300. that contain modifiers other than Command. (All letters delivered in
  3301. lower case:  check shiftKey bit).
  3302. I highly recommend that you read up on KeyTranslate() - nothing here is
  3303. hard except getting kchrResPtr.
  3304. */
  3305.  
  3306. #include <Events.h>
  3307. #include <Script.h>
  3308.  
  3309. // Locals - set up here and then leave alone
  3310. // breaking kchrResPtr into 2 parts and putting in constructor saves a few bytes
  3311. static UInt32 state = 0;
  3312. static Ptr kchrResPtr =
  3313. *::RGetResource('KCHR',::GetScriptVariable(::GetScriptManagerVariable(smKeyScript),
  3314. smScriptKeys)); 
  3315.  
  3316.  
  3317. static void StripModifiers(EventRecord &inMacEvent);
  3318.  
  3319. void StripModifiers(EventRecord &inMacEvent) {
  3320.    // Look up KeyTranslate() for the key to this: virtual keycode in low byte,
  3321.    // modifiers (0) in upper.  Assumes this is a key DOWN event.
  3322.    short modKeyCode = (inMacEvent.message & keyCodeMask) >> 8;
  3323.    modKeyCode = ::KeyTranslate(kchrResPtr,modKeyCode,&state);
  3324.    inMacEvent.message = (inMacEvent.message & ~charCodeMask) | (modKeyCode
  3325. & charCodeMask);
  3326.    }
  3327.  
  3328. +++++++++++++++++++++++++++
  3329.  
  3330. >From rdwells@mmm.com (Richard Wells)
  3331. Date: 20 Sep 1995 15:05:14 GMT
  3332. Organization: 3M Company
  3333.  
  3334. reed@medicine.wustl.edu (Thomas Reed) wrote:
  3335. >I need to capture and display a user's keypress.  For instance, if the
  3336. >user presses cmd-opt-p, I want to display "Command + Option + p". 
  3337. >Unfortunately, when I get the key pressed from the EventRecord, it is the
  3338. >MODIFIED key -- for instance, the character from the above keypress would
  3339. >be pi.  This is obviously not what I want -- I don't want to display
  3340. >"Command + Option + pi"!
  3341. >
  3342. >So...  is there any way that I can modify this character to get the raw
  3343. >character rather than the modified character?
  3344.  
  3345. Unless I misunderstand you, the information you need is contained
  3346. in the event record.  The 'message' field contains the virtual key
  3347. code as well as the character it translates to.
  3348.  
  3349. _Inside Macintosh: Macintosh Toolbox Essentials_ contains pictures
  3350. of which keys on various keyboards generate which virtual key codes.
  3351.  
  3352.  
  3353.  
  3354. +++++++++++++++++++++++++++
  3355.  
  3356. >From munz@wordperfect.com (Mark Munz)
  3357. Date: Fri, 22 Sep 1995 08:40:38 -0600
  3358. Organization: Novell, Inc.
  3359.  
  3360. In article <43paja$l43@dawn.mmm.com>, rdwells@mmm.com (Richard Wells) wrote:
  3361.  
  3362. > >So...  is there any way that I can modify this character to get the raw
  3363. > >character rather than the modified character?
  3364. > Unless I misunderstand you, the information you need is contained
  3365. > in the event record.  The 'message' field contains the virtual key
  3366. > code as well as the character it translates to.
  3367. > _Inside Macintosh: Macintosh Toolbox Essentials_ contains pictures
  3368. > of which keys on various keyboards generate which virtual key codes.
  3369.  
  3370. One note, if you use the Event Manager, you'll have to watch for dead-key
  3371. issues. An app never sees the first dead-key hit (opt-N). You'll either
  3372. have to setup your own Keyboard resource, or use something like GetKeys to
  3373. grab info from the keyboard.
  3374.  
  3375. Mark Munz
  3376.  
  3377. ---------------------------
  3378.  
  3379. End of C.S.M.P. Digest
  3380. **********************
  3381.